//prime number using function
#include<stdio.h>
int prime(int);
int main()
{
int num,val;
clrscr();
printf("Enter the number:");
scanf("%d",&num);
val=prime(num);
if(val==0)
printf("\nNumber is not prime\n");
else
printf("\nNumber is prime\n");
getch();
}
int prime(int a)
{
int i,count=0;
for(i=2;i<a/2;i++)
{
if((a%i)==0)
{
break;
}
else
count++;
}
if(count>0)
return 1;
else
return 0;
}
Prime numbers are numbers which are not divisible by any number other than 1 and itself. Here is the C program to print all prime numbers between 1 to N. We can also check for prime numbers in C.
ReplyDelete