c program to check number is prime or not

Program Code


// Check whether given number is prime number and not prime number
#include "stdio.h"
#include "conio.h"
void main()
{
int num,i,z;
printf("enter the value of num");
scanf("%d",&num);
i= 2;
while (i less then num)
{
if(num%i==0)
{
z=1;
}
i=i+1;
}
printf("After checking the result is");
if(z== 1)
{
printf("given number is not prime number");
}
else
{
printf("given number is prime number");
}
getch();
}

Input/Output


enter the value of num 7
After checking the result is
given number is prime number


What is Prime Number?


Prime number is a natural number which is divisible by 1 and itself.
Example 7

First 25 Prime Number :-
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

Post a Comment

0 Comments