summaryrefslogtreecommitdiff
path: root/cbook/one_two.c
blob: a5bf2211e4302157af554ec44004e950b5293688 (plain)
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
27
28
29
30
31
32
33
34
35
36
/*
*
* Dumb program that generates prime numbers.
*/
#include <stdio.h>
#include <stdlib.h>


int is_prime(int x) {
    for (int i=2; i<x; i++) {
        if (x % i == 0 && i != x) return 0;
    }
    return 1;
}




int main(){
    int this_number, prime, next_prime, next_number;

    this_number = 3;

    while(this_number < 10000){
        prime = is_prime(this_number);
        if (prime == 1) {
            next_number = this_number + 2;
            next_prime = is_prime(next_number);
            if (next_prime == 1)
                printf("%d and %d are prime pair\n", this_number, next_number);
        }
        this_number++;

    }
    exit(EXIT_SUCCESS);
}