#include<stdio.h>
#include<conio.h>
#include<math.h>
int prime(int n, int i)
{
if(i<=sqrt(n))
{
if(n%i==0)
return(i);
i=prime(n,i+1); //Recursion: Function calling itself
}
//printf("%d",i);
return(i);
}
int main()
{
int n,t;
char ans;
//clrscr();
do{
printf("\n enter any number: ");
scanf("%d",&n);
t=prime(n,2);
if(t>sqrt(n))
printf("\n your number %d is prime number",n);
else
printf("\n your number %d is not prime",n);
fflush(stdin); //clean the garbage of standard input stream before taking input
printf("\n Want to continue (y/n): ");
scanf("%c",&ans);
}while(ans=='y'||ans=='Y');
//getch(); //use getch() in TurboC++ to hold the console
return 0;
}
No comments:
Post a Comment