Prime Number Program || C language
Prime Number Program in C Language With fastest speed. If you didn't get the Logic Mail at Learndphere@gmail.com Follow us at The Cobox - Knowledge is Growth
Prime Number Program in C Language With fastest speed.
If you didn't get the Logic Mail at Learndphere@gmail.com
Follow us at The Cobox - Knowledge is Growth
#include
int main()
{
int number, startPoint, endpoint, flag;
printf("Enter number to find prime: ");
scanf("%d", &number);
if(number <= 1){
printf("Number is not prime");
return 0;
}
flag = 0; // To validate existance
startPoint = 2; // 1 and 0 will always show same results and they are not prime also
endpoint = number/2; // making number/2 becuase more then half of number will not be divisble
while(startPoint <= endpoint){
if(number % startPoint == 0){
flag = 1;
break;
}
startPoint++;
}
if(flag == 0)
printf("%d is a prime Number", number);
else
printf("%d is Not a prime Number", number);
return 0;
}