 # problem on C

write a c program to ask for a number from the user, and then find the next prime no and show it as the output

#include <stdio.h>
#include <math.h>

``````#define TRUE 1
#define FALSE 0

/* Prototypes */
int isPrime(int input);

int main(void){

}

/* Function for determining the next prime number */

int inputNumber = 1;

while(inputNumber != 0){
scanf("%d", &inputNumber);

if(inputNumber<=0){
printf("The number you have entered is zero or negative.\n");
exit(0);
}

/* if the number is even, make it odd (2 is special case) */
}

/* while its not a prime number, check the next odd number */
}

printf("The prime number following %d is %d\n", inputNumber, nextPrimeNumber);
}
return 0;
}

/* Function that checks whether or not a given number is
* a prime number or not.
*/
int isPrime(int input){
int i;

int prime = TRUE;

if(input == 2){
return TRUE;
}

if(input%2 == 0 || input <= 1){
prime = FALSE;
} else {
for(i=3; i<=sqrt(input); i+=2){
if(input%i == 0){
prime = FALSE;
}
}
}
return prime;
}
``````

And yes, Source:Internet

1 Like