Advertisement
Guest User

c linux

a guest
Apr 26th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5. int Sprawdz(int x) {
  6.     int i;
  7.  
  8.     for(i=2; i<x; ++i) {
  9.         if(x==i) continue;
  10.         if(x%i == 0) return 0;
  11.     }
  12.     return 1;
  13. }
  14.  
  15. int main(void)
  16. {
  17.     FILE *plik = open("wyniki.txt", "w+");
  18.     if(!plik) return 0;
  19.  
  20.     int i;
  21.     int foo = fork();
  22.    
  23.     if(foo) {
  24.         for(i=2; i<=100; ++i) {
  25.             if(Sprawdz(i)) {
  26.                 fprintf(plik, "%d \n", i);
  27.             }
  28.         }
  29.     }
  30.  
  31.     if(foo==0) {
  32.         for(i=100; i<=200; ++i) {
  33.             if(Sprawdz(i)) {
  34.                 fprintf(plik, "%d \n", i);
  35.             }
  36.         }
  37.     }
  38.  
  39.     if(foo) {
  40.         int buff;
  41.         fseek(plik, 0, SEEK_SET);
  42.         while(!feof(plik)) {
  43.             fscanf(plik, "%d", &buff);
  44.             printf("%d \n", buff");
  45.         }
  46.     }
  47.    return EXIT_SUCCESS;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement