C Program to Check Whether a given Number is Prime or Not
In this example, we will check whether a given number is Prime or Not. To solve this problem we should know about Prime Numbers.
What is a Prime Number?
Prime Numbers are those numbers which can only be divisible by 1 and the number itself.
For Example: 2,3,5,7,etc are prime numbers, as these numbes are only divisible by 1 and the number itself.
PROGRAM:
#include<stdio.h>
#include<conio.h>
int main()
{
int x,i,count=0;
printf("\nEnter the number : ");
scanf("%d",&x);
for(i=1;i<=x;i++)
{
if(x%i==0)
count++;
}
if(count==2)
{
printf("\n%d is a Prime Number",x);
}
else
{
printf("\n%d is Not a Prime Number",x);
}
}
OUTPUT:
Enter the number : 5
5 is a Prime Number
NOTE: You Can Comment Your Code if you have solved differently and we will pin it in the comment section. Let's Learn together.
MOTTO:
You Learn, I Learn together We Learn.
Comments
Post a Comment
Please do not spam any link