#include<stdio.h>

#include<conio.h>

int prime();

int main()

{

int n, i, flag=0;

clrscr();

// no argument is passed to the function

// the value returned from the function is assigned to n

n = prime();

for(i=2; i<=n/2; ++i)

{

if(n%i==0)

{

flag = 1;

break;

}

}

if (flag == 1)

printf(“%d is not a prime number.”, n);

else

printf(“%d is a prime number.”, n);

getch();

return (0);

}

// prime() function returns integer entered by the user

int prime()

{

int n;

printf(“Enter a positive integer: “);

scanf(“%d”,&n);

return(n);

}

Output :-

Advertisements