A prime number is a number that can be evenly divided by onl
Solution
The program in c is as follows:
#include<stdio.h>
#include <stdbool.h> //include this directory in your program for boolean function declaration
main()
{
int n, result;
printf(\"Enter an integer to check whether it is prime or not.\ \");
scanf(\"%d\",&num);
result = check_prime(num);
//applying check for the returned result
if ( result == 1 )
printf(\"prime.\ \");
else
printf(\" not prime.\ \");
return 0;
}
//boolean function to check if the number is prime or not
bool prime(int num)
{
int i;
for ( i = 2 ; i <= num - 1 ; i++ )
{
//if the number is divisible by any of the number then it is not boolean hence return false
if ( num%i == 0 )
return false;
}
//if the number is not divisible by any number from the loop then counter i reaches till the num hence it is prime
if ( i == num )
return true;
}
