Prime number in C: Here we discuss about program for how to check whether number is prime or not.
![]() |
C Prime Number Program |
In this post we are going to see c prime number program. in which we will see how to check where given number is prime number or not a prime number through a very simple logic in c prime number program.
Before that for your better understanding we will see what is prime number means-
what is prime number?
"prime number is nothing but the number which can be divisible by only '1' and 'itself number' only."
means a number which cant be decide by any other number other than 1 and itself number.
for example: suppose 5 is a number. 5 can be only divisible by 1 and 5, so that it is prime number. take another number 6, 6 can be divisible by 1,2,3 and 6, so that it is not a prime number.
hope you understand logic of prime number. lets see how to write c prime number program.
c prime number program
#include<stdio.h>
# include<conio.h>
void main()
{
clrscr();
int num=0,count=0,i=0;
printf("Enter any number to check where it is prime or not:");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
if(num%i==0)
count=count+1;
}
if(count==2)
{
printf("Entered Number is a Prime Number");
}
else
{
printf("Entered Number is Not a Prime Number");
}
getch();
}
Output:
Enter any number to check where it is prime or not: 5
Entered Number is a Prime Number
hope you have understand the prime number program in c. if you have still any concern about it you can fill free to ask in comment box.
Post a Comment