Need help please , this homework is not complete... programming problem 3.21 cod
ID: 3790105 • Letter: N
Question
Need help please , this homework is not complete...
programming problem 3.21 code is
#include<stdio.h>
int main()
{
int a;
scanf("%d",&a);
while (a!=1)
{
printf("%d ",a);
if (a%2==0)
a=a/2;
else
a=3*a+1;
printf("%d ",a);
}
return 0;
}
--------
<<<<<<the above code is
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{ pid_t pid, pid1;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed"); return 1;
}else if (pid == 0) { /* child process */ pid1 = getpid();
printf("child: pid = %d ",pid); /* A */
printf("child: pid1 = %d ",pid1); /* B */
}else { /* parent process */
pid1 = getpid();
printf("parent: pid = %d ",pid);
/* C */ printf("parent: pid1 = %d ",pid1); /* D */
wait(NULL);
}
return 0;
}
what I need exactly combine those to program and make it one . for example look at the picture ...
Purpose of This Assignment To provide experience with process creation in Unix Problem Statement: Programming problem 3.21 (page 155), with the following extra information/requirements: 1. Besides requirements in Problem 3.21, your program should also display the process IDs of both the parent and child processes. Follow the code in Figure 3.34 (page 152) to structure your program and to print the process IDs. Capture a screenshot after running your program A sample screenshot is provided below (the output of your program should have the same structure as in the sample screenshot 2. A skeleton of the program is provided in D2L, which has code to obtain user's input number from command line. Add your own code on top of the existing code. 3. You can use the gcc command to compile the program. See the sample screenshot below What to submit (submit through iCollege): Upload program file hw1.c and a project report (named as "FirstName LastName HW1.pdf" or "FirstName LastName HWI doc") to D2L. The project report should include 1) a sample screenshot of the output; 2 the source code of hw1.c.Explanation / Answer
#include<stdio.h>
#include <sys/types.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
pid_t pid, pid1;
int a;
/* fork a child process */
pid = fork();
if (pid < 0) { /* error occurred */
fprintf(stderr, "Fork Failed"); return 1;
}else if (pid == 0) { /* child process */ pid1 = getpid();
printf("child: pid = %d ",pid); /* A */
printf("child: pid1 = %d ",pid1); /* B */
}else { /* parent process */
pid1 = getpid();
printf("parent: pid = %d ",pid);
/* C */ printf("parent: pid1 = %d ",pid1); /* D */
wait(NULL);
}
scanf("%d",&a);
while (a!=1)
{
printf("%d ",a);
if (a%2==0)
a=a/2;
else
a=3*a+1;
printf("%d ",a);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.