In the Mini project, 4th module is to find whether the number is prime or not. Rita allotted this function to Sonia.
Help Sonia to write a program to find whether the given number is prime or not.
Function Specification:
int findprime (int n); - should return 1 if n is prime, else 0.
Input Format:
Input consists of 1 integer.
Output Format:
The output consists of a single integer. Display 1 if the number is prime and 0 if the number is not prime.
Refer sample input and output for formatting details.
Sample Input 1:
3
Sample Output1:
1
Sample Input 2:
9
Sample Output2:
0
Program Code:
#include<stdio.h>
int findprime (int);
int main()
{
int n, result;
scanf("%d",&n);
result = findprime (n);
if ( result == 1 )
printf("%d", result);
else
printf("%d", result);
return 0;
}
int findprime(int a)
{
int c;
for ( c = 2 ; c <= a - 1 ; c++ )
{
if ( a%c == 0 )
return 0;
}
return 1;
}
Post A Comment:
0 comments: