/[cvs]/joko/Uni/BSArch/01/prime.c
ViewVC logotype

Annotation of /joko/Uni/BSArch/01/prime.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (hide annotations)
Fri May 12 19:03:04 2006 UTC (18 years, 6 months ago) by joko
Branch: MAIN
Changes since 1.2: +2 -0 lines
File MIME type: text/plain
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 RSS 2.0 feed