Created
October 1, 2016 19:37
-
-
Save towkir/63545a3376f7c7fd68a33e0c97d650cf to your computer and use it in GitHub Desktop.
This C program checks an input number and replies with the result after checking if the number is prime.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int number; | |
printf("Enter your number:\n"); | |
scanf("%d", &number); | |
if (number > 3){ // 1,2,3 are prime for sure; verification starts for bigger numbers; | |
for (int i = 2; i<number; i++){ | |
if (number % i == 0){ | |
printf("The number is not a prime number.\n"); | |
break; | |
} | |
else { | |
printf("The number is prime.\n"); | |
break; | |
} | |
} | |
} else { | |
printf("The number is prime.\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment