Write a C program in ‘c’ to find given positive number is prime number or not.
Ans:
#include<stdio.h>
#include<conio.h>
void main()
{
int I,n;
int I,n;
int ctr=0;
printf(“enter any no\n”);
scanf(“%d”&n);
for(i=1;<=n;i++)
{
if(n%i==0)
{
ctr++;
}
}
if(ctr==2)
{
printf(“%d is prime no\n”);
}
else
else
{
printf(“%d is not a prime no\n”);
}
getch();
No comments:
Post a Comment