C Program To Find Prime Number Using Function
In this article, we are going to write a C Program To Find Prime Number Using Function
To make this program, we will use the following concept given below.
If you do not know about these topics well, then you may not understand this program, so you should know about them in detail from the link given above.
Now without wasting time let’s start programming.
C Program To Find Prime Number Using Function
Algorithm
- Program Start
- Declare Variables
- Input A Number to check prime or not
- Calling Function
- Declare some variable
- Loop Start
- Check conditions
- Disoplay result according to condition
- Function End
- Program End
Program
//C Program to check prime number Using Function
#include <stdio.h>
void checkPrime(int n)
{
int i, count = 0;
for(i=2; i<n; ++i)
{
// check for non prime number
if(n%i==0)
{
count=1;
break;
}
}
if (count==0)
printf("%d is a prime number.",n);
else
printf("%d is not a prime number.",n);
}
int main()
{
int n;
printf("Enter a number to check prime number or not : ");
scanf("%d",&n);
checkPrime(n);
}
Output
Enter a number to check prime number or not : 10
10 is not a prime number.
Read More
- Download C Language Notes Pdf
- C Language Tutorial For Beginners
- C Programming Examples With Output
- 250+ C Programs for Practice PDF Free Download
Conclusion
So friends, in this article, we have written a Prime Number Program In C Using Function
If you have difficulty to understand any program or have any doubts or questions, then tell me in the comment below.