Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Execute in a single program all of these, C programming Each child process start

ID: 3824662 • Letter: E

Question

Execute in a single program all of these, C programming

Each child process starts one new program from a set of five possible new programs.

The five test programs are as follows:

1. test1.c: Prints values from 0 to 4, along with the square of each value.

2. test2.c: Calculates and prints the square root of the PID.

3. test3.c: Determines whether the PID is odd or even.

4. test4.c: Calculates and prints the number of digits in the PID.

5. test5.c: Uses a recursive quicksort function to sort an array of ten integers.

Explanation / Answer

1)

source code:

#include<stdio.h>
int main(){
int pow,num,i=1;
long int sum=1;
printf(" Enter a number: ");
scanf("%d",&num);
printf(" Enter power: ");
scanf("%d",&pow);
while(i<=pow){
sum=sum*num;

i++;
}
printf(" %d to the power %d is: %ld",num,pow,sum);
return 0;
}

2

source code:

#include<stdio.h>
#include<conio.h>
#include<math.h>

void main()
{
float a,b,c,root1,root2;
clrscr();
printf(“ Enter values of a,b,c for finding roots of a quadratic eq: ”);
scanf(“%f%f%f”,&a,&b,&c);
/*checking condition*/
if(b*b>4*a*c)
{
   root1=-b+sqrt(b*b-4*a*c)/2*a;
   root2=-b-sqrt(b*b-4*a*c)/2*a;
   printf(“ *****ROOTS ARE***** ”);
   printf(“ root1=%f root2=%f”,root1,root2);
}
else
   printf(“ Imaginary Roots.”);
getch();
}

3.

source code

#include <unistd.h>

#include <stdio.h>

int main()

{

  int   i;

  pid_t pid;

  for(i = 0; i < n; i ++)

  {

    pid = fork();

    if(pid == 0) break;

  }

  if(pid == 0)

  {

  }

  else

  {

  }

}