Write a C program that will keep asking the user to enter a

Write a C program that will keep asking the user to enter a non-negative integer smaller than 65000, check if it is a prime number or not and print a corresponding message indicating its type. The program should keep doing this until the user enters zero. Also, code checking prime number should be carried out by writing a function that takes a number and return 1 if it is a prime number and zero otherwise.

Solution

#include<stdio.h>

void chkprime();

void main(){

chkprime();

getch();

return 0;

}

void chkprime(){

int input;

int i;

int count=0;

while(1){

printf(\"enter input\");

scanf(\"%d\",&input);

if(input>65000)

printf(\"you have entered greater value:\");

else if(input==0)

exit(0);

else{

for(i=1;i<=input;i++){

if(input%i==0)

count++;

}

if(count==2)

printf(\"%d is prime\",input);

else

printf(\"%d is not prime\",input);

count=0;

}

}

Write a C program that will keep asking the user to enter a non-negative integer smaller than 65000, check if it is a prime number or not and print a correspond
Write a C program that will keep asking the user to enter a non-negative integer smaller than 65000, check if it is a prime number or not and print a correspond

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site