We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c5c05c2 commit f79b3a5Copy full SHA for f79b3a5
Program to Check Prime Number
@@ -0,0 +1,28 @@
1
+#Program to Check Prime Number
2
+#include <stdio.h>
3
+int main() {
4
+ int n, i, flag = 0;
5
+ printf("Enter a positive integer: ");
6
+ scanf("%d", &n);
7
+
8
+ for (i = 2; i <= n / 2; ++i) {
9
10
+ // condition for non-prime
11
+ if (n % i == 0) {
12
+ flag = 1;
13
+ break;
14
+ }
15
16
17
+ if (n == 1) {
18
+ printf("1 is neither prime nor composite.");
19
20
+ else {
21
+ if (flag == 0)
22
+ printf("%d is a prime number.", n);
23
+ else
24
+ printf("%d is not a prime number.", n);
25
26
27
+ return 0;
28
+}
0 commit comments