So I'm learning about forks and decided to do this program as a practice but it's executing scan twice (the program waits for a second input which basically does nothing!)
int n;
printf("Enter a number: ");
scanf("%d\n",&n);
if(fork()){ //p1
wait(NULL);
printf("Finished displaying factorial and summation\n");
}else if(fork()){ //p2
wait(NULL);
long fact=1;
for(int j=1; j<=n; j++)
fact*=j;
printf("factorial of %d: %ld\n",n,fact);
}else{ //p3
int sum=0;
for(int i=1; i<=n;i++)
sum +=i;
printf("summation: %d\n",sum);
}