This program asks the user to find out the prime number. For this user declare the variables that use to store the value in it. User declare two int variables one of them value assign b=2 and put them on a while condition. While (a>1) then passes to control statement if (a%b==0) then a=a/b else b=b+1 and get the output on screen as result. That will show the output is prime numerical or not.
Problem Statement:
This is C Program to check whether the number is prime or not.
- Declaring the variable.
- Using conditions as required.
- Display result on the screen.
Here is C source code for check out the prime number. Output of this program shown below.
#include<stdio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the no. :");
scanf("%d",&a);
b=2;
while(a>1)
{
if(a%b==0)
{
printf("%d",b);
a=a/b;
}
else
{
b=b+1;
}
}
getch();
}