Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- int main(int argc,char *argv[]) {
- int num=0,num2=0, total=1, cont=0,valor,total1=1,total2=1,resultado;
- FILE *arquivo1, *arquivo2,*arquivo3,*arquivo4;
- arquivo1=fopen("arq1.txt","r");
- arquivo2=fopen("arq2.txt","r");
- arquivo3=fopen("arq3.txt","r");
- arquivo4=fopen("arq4.txt","r");
- pid_t var1, var2;
- num = atoi(argv[1]);
- num2=num/2;
- valor=num;
- var1=fork();
- if ( var1 == 0 )
- {
- fscanf(arquivo1,"%d",&num);
- fclose(arquivo1);
- for (cont = num; num > 1; num--) {
- total1 = total * (num);
- fprintf(arquivo3,"%d",total1);
- }}
- var2=fork();
- if ( var2 == 0 )
- {
- fscanf(arquivo2,"%d",&num);
- fclose(arquivo2);
- for (cont = num; num > 1; num--) {
- total2 = total * (num);
- fprintf(arquivo4,"%d",total2);
- }}
- waitpid(var1,&total1,0);
- waitpid(var2,&total2,0);
- fscanf(arquivo3,"%d",&total1);
- fscanf(arquivo4,"%d",&total2);
- resultado=total1*total2;
- printf("%d",resultado);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement