C program to find that given number is prime or not using function.

#include<stdio.h>
#include<conio.h>
main(){
int n,x;
int prime( int );
clrscr();
printf("enter a number\n");
scanf("%d",&n);
if (n==1) {
printf("%d is universal prime number\n");
}
else { 
x=prime(n);
if (n==x)
printf("%d is prime number\n",n);
else 
printf("%d is not a prime number\n",n);
}
getch();
return 1;
}
int prime( int y){
int i;
for (i=2;i<y;i++){
if (y%i==0)
return i;
}
return i;
}

No comments:

Post a Comment