1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#include <stdio.h>
#include<stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/types.h>
#define INF 99999999
int main()
{
int N1,N2;
puts("Please Type Your First Number: ");
scanf("%d",&N1);
puts("Please Type Your Second Number : ");
scanf("%d",&N2);
puts(" Thank You: ");
int counter = 0;
pid_t pid = fork();
if (pid == 0)
{
// child process
int sum = N1 + N2;
int diff = N1 - N2;
printf("\n The Sum of %d and %d is %d and The Diff is %d",N1,N2,sum,diff);
exit(0);
}
else if (pid > 0)
{
// parent process
wait(NULL);
double div;
int mul = N1 *N2;
if(N2!=0)
{
div = (double)N1/(double)N2;
printf("\n The Multiplication of %d and %d is %d and The Division is %lf",N1,N2,mul,div);
}
else
{
div=INF;
printf("\n The Multiplication of %d and %d is %d",N1,N2,mul);
printf("\n Denominator cannot be zero!Operation division not possible.");
}
}
else
{
// fork failed
puts("fork() failed!\n");
return 1;
}
return 0;
}
|