Parent Directory | Revision Log
changed newlines from CR to LF
1 | joko | 1.1 | #include <stdio.h> |
2 | #define PRINTPRIME(x) if(prime(x)) printf("%i\n", x) | ||
3 | joko | 1.3 | |
4 | joko | 1.1 | int prime(int number) |
5 | { | ||
6 | int i; | ||
7 | for(i=2;i*i<=number;i++){ | ||
8 | if((number%i) == 0) | ||
9 | return 0; | ||
10 | } | ||
11 | return 1; | ||
12 | } | ||
13 | joko | 1.3 | |
14 | joko | 1.1 | int main(int argc, char * argv[]) |
15 | { | ||
16 | int i, j; | ||
17 | FILE * fp; | ||
18 | char num[11]; | ||
19 | if(argc > 2 ){ | ||
20 | j=atoi(argv[2]); | ||
21 | for(i=atoi(argv[1]) ; i< j; i++){ | ||
22 | PRINTPRIME(i); | ||
23 | } | ||
24 | }else { | ||
25 | fp=fopen(argv[1], "r"); | ||
26 | if(fp==NULL){ | ||
27 | PRINTPRIME(atoi(argv[1])); | ||
28 | }else{ | ||
29 | while(fgets(num, 11, fp)) | ||
30 | PRINTPRIME(atoi(num)); | ||
31 | fclose(fp); | ||
32 | } | ||
33 | } | ||
34 | } |
MailToCvsAdmin">MailToCvsAdmin | ViewVC Help |
Powered by ViewVC 1.1.26 |