external_4.c
Source Code
Printing the code
To print this file, open it on GitHub and click Raw before printing, or use the Download Raw button above and print directly from that page.
c
#include<stdio.h>
int isPrime(int);
int main() {
int num, i;
printf("Enter the number: ");
scanf("%d", &num);
if(isPrime(num)) printf("\n%d is a prime number.", num);
else printf("\n%d is not a prime number.", num);
// generate prime numbers upto 100
printf("\n\nPrime number upto 100: ");
for(i = 1; i <= 100; i++) {
if(isPrime(i)) printf("\n%d ", i);
}
return 0;
}
int isPrime(int n) {
int i;
if(n == 2) return 1;
if(n <= 1 || n % 2 == 0) return 0;
for(i = 3; i * i <= n; i = i+2) if(n % i == 0) return 0;
return 1;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26