6. write a C program that finds if a given number is prime number or not


Program that finds if a given number is prime number or not

Source Code:

#include<stdio.h>
int main()
{
int i,n,count=0;
printf("enter the value of n:\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
if(count==2)
{
printf("prime number");
}
else
{
printf("not a prime number");
}
}

OutPut:

enter the value of n:
17
prime number

No comments:

Post a Comment