system7

Prímszámok

Oct 23rd, 2011
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #include <conio.h>
  4. #define N 1000000000
  5. int main()
  6. {
  7.     FILE *f;
  8.     int szam, oszto;
  9.     f=fopen("e:\\prim.txt","w+t");
  10.     if (f==NULL)
  11.         {
  12.             printf("Nincs meg a hiba fájl!");
  13.             return 1;
  14.         }
  15.     for (szam=500000000;szam<N;szam++)
  16.         {
  17.             oszto=2;
  18.             while (oszto<=sqrt(szam) && (szam % oszto !=0))
  19.                 oszto++;
  20.             if (oszto>sqrt(szam))
  21.                 {
  22.                     fprintf(f,"%d, ",szam);
  23.                     printf("%d",szam);
  24.                 }
  25.         }
  26.     fclose(f);
  27.     printf("\a");
  28.     return 0;
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment