Advertisement
Guest User

Untitled

a guest
May 27th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/types.h>
  4.  
  5. int main(int argc,char *argv[]) {
  6.  
  7. int num=0,num2=0, total=1, cont=0,valor,total1=1,total2=1,resultado;
  8. FILE *arquivo1, *arquivo2,*arquivo3,*arquivo4;
  9.  
  10. arquivo1=fopen("arq1.txt","r");
  11. arquivo2=fopen("arq2.txt","r");
  12. arquivo3=fopen("arq3.txt","r");
  13. arquivo4=fopen("arq4.txt","r");
  14.  
  15. pid_t var1, var2;
  16.  
  17. num = atoi(argv[1]);
  18. num2=num/2;
  19. valor=num;
  20.  
  21. var1=fork();
  22. if ( var1 == 0 )
  23. {
  24. fscanf(arquivo1,"%d",&num);
  25. fclose(arquivo1);
  26. for (cont = num; num > 1; num--) {
  27. total1 = total * (num);
  28. fprintf(arquivo3,"%d",total1);
  29. }}
  30. var2=fork();
  31. if ( var2 == 0 )
  32. {
  33. fscanf(arquivo2,"%d",&num);
  34. fclose(arquivo2);
  35. for (cont = num; num > 1; num--) {
  36. total2 = total * (num);
  37. fprintf(arquivo4,"%d",total2);
  38. }}
  39. waitpid(var1,&total1,0);
  40. waitpid(var2,&total2,0);
  41.  
  42. fscanf(arquivo3,"%d",&total1);
  43. fscanf(arquivo4,"%d",&total2);
  44.  
  45. resultado=total1*total2;
  46. printf("%d",resultado);
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement