/[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.1 - (hide annotations)
Fri May 12 18:41:34 2006 UTC (18 years, 6 months ago) by joko
Branch: MAIN
File MIME type: text/plain
+ initial commit (from franky)

1 joko 1.1 #include <stdio.h>
2     #include <math.h>
3     #define PRINTPRIME(x) if(prime(x)) printf("%i\n", x)
4     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     int main(int argc, char * argv[])
14     {
15     int i, j;
16     FILE * fp;
17     char num[11];
18     if(argc > 2 ){
19     j=atoi(argv[2]);
20     for(i=atoi(argv[1]) ; i< j; i++){
21     PRINTPRIME(i);
22     }
23     }else {
24     fp=fopen(argv[1], "r");
25     if(fp==NULL){
26     PRINTPRIME(atoi(argv[1]));
27     }else{
28     while(fgets(num, 11, fp))
29     PRINTPRIME(atoi(num));
30     fclose(fp);
31     }
32     }
33     }

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed