![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEib_ZR9Fg8swBXMmI3jRhYpD_BWLOrV0664XLh2XJAyHGN7kaxAJpnyn7bjhi4NnV5Ecsr_2jzMRDUkIyxhqbbnPhVZdGZwMxh0SIC-fSwMszVi-Y6CoXjhNKeEaVLm9m1H4rQiRtWWqGYf/s640/Program+to+check+prime+number.jpg)
by using following program user can check the entered number is prime or not.
Program:
//C program to check whether the number is prime or not. By slashmycode.com
#include<stdio.h>
#include<conio.h>
void main()
{
int n, result;
printf("Enter an integer to check whether it is prime or not.\n");
scanf("%d",&n);
result = check_prime(n);
if ( result == 1 )
printf("%d is prime.\n", n);
else
printf("%d is not prime.\n", n);
return 0;
}
int check_prime(int a)
{
int c;
for ( c = 2 ; c <= a - 1 ; c++ )
{
if ( a%c == 0 )
return 0;
}
if ( c == a )
//C program to check whether the number is prime or not. By slashmycode.com
return 1;
}
Output:
No comments:
Post a Comment
Feel free to ask us any question regarding this post