Program to find prime number using function & goto in C

Prime Number is a number which is divisible only by 1 and itself . In other word such integer which is not divisible by any other integer except 1 and itself ..

 

Code

int isPrime(int num);
void main()
{
int num,ans;
char res;
h:
clrscr();
printf(“Enter any Number:->>”);
scanf(“%d”,&num);
if(isPrime(num))
printf(“Number is Prime”);
else
printf(“Number is not prime”);
printf(“\nDo you want to continue(Y/N):->>”);
res=getch();
if(res==’y’)
goto h;
else
exit(0);
goto h;
}
int isPrime(int num)
{
int i,end;
end=num/2;
for(i=2;i<=end;i++)
{
if(num%i==0)
return 0;

}
return 1;
}

Output

 

Leave a Reply