mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 23:09:36 +03:00
23 lines
417 B
C
23 lines
417 B
C
#include <stdio.h>
|
|
#include <math.h>
|
|
|
|
int isPrime(int x) {
|
|
for (int i = 2; i < sqrt(x); i++) {
|
|
if (x%i == 0)
|
|
return 0;
|
|
}
|
|
return 1;
|
|
|
|
}
|
|
|
|
int main() {
|
|
int a;
|
|
printf("Input a number to see if it is a prime number:\n");
|
|
scanf("%d", &a);
|
|
if (isPrime(a))
|
|
printf("%d is a prime number.\n", a);
|
|
else
|
|
printf("%d is not a prime number.\n", a);
|
|
return 0;
|
|
}
|