Question

Develop c program and give me screenshot of output? Develop a program that accepts integers from...

Develop c program and give me screenshot of output?

Develop a program that accepts integers from command line and uses fork() to have 4 child processes that will do sorting the integers into ascending order, computing the sum of the integers, and counting the number .of even numbers and the number of odd numbers respectively.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
   int array[100],pid1,pid2,pid3,pid4,n,i,j,temp,sum,e,o;
   printf("Enter How many integers: ");
   scanf("%d",&n);
   for (i=0;i<n;i++)
   {
       printf("Enter %d integer: ",i+1);
       scanf("%d",&array[i]);
   }
   pid1=fork();
   if (pid1==0)
   {
       // Sorting
       for (i=0;i<n;i++)
       {
           for (j=0;j<n-1;j++)
           {
               if (array[j]>array[j+1])
               {
                   temp=array[j];
                   array[j]=array[j+1];
                   array[j+1]=temp;
               }
           }
       }
       printf(" After sort the Integers are ");
       for (i=0;i<n;i++)
           printf("%d ",array[i]);
   }
   else
   {
       pid2=fork();
       if (pid2==0)
       {
           sum=0;
           for (i=0;i<n;i++)
               sum+=array[i];
           printf(" Sum of Integers = %d ",sum);
       }
       else
       {
           pid3=fork();
           if (pid3==0)
           {
               e=0;
               for (i=0;i<n;i++)
               {
                   if (array[i]%2==0)
                       e++;
               }
               printf(" Even Integers = %d ",e);
           }
           else
           {
               pid4=fork();
               if (pid4==0)
               {
                   o=0;
                   for (i=0;i<n;i++)
                   {
                       if (array[i]%2!=0)
                           o++;
                   }
                   printf(" Odd Integers = %d ",o);
               }
               else
                   printf(" ");
           }
       }
   }
   return 0;
}

The output may not be in order because of calling child/parent process. It is upto the compiler.

Add a comment
Know the answer?
Add Answer to:
Develop c program and give me screenshot of output? Develop a program that accepts integers from...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Develop a program that accepts integers from command line, sorts the integers into ascending order, computes...

    Develop a program that accepts integers from command line, sorts the integers into ascending order, computes the sum of the integers, and counts the number of even numbers and the number of odd numbers. Solve in C programing language?

  • 2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

    2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user. Write a Marie program that accepts two positive integers, multiples them by repeated addition, and...

  • WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH...

    WRITE A PROGRAM IN C++ THAT DECLARES AN INTEGER VECTOR V 1.)INITIALIZE THE VECTOR, V, WITH 10 INTEGERS WITH VALUES FROM 1 TO 10 2.)OUTPUT THE VECTOR IN DESCENDING ORDER, THEN ASCENDING ORDER 2.)ADD ALL THE EVEN NUMBERS 3.)ADD ALL THE ODD NUMBERS 4.)OUTPUT THE SUM OF EVEN INTEGERS 5.)OUTPUT THE SUM OF ODD INTEGERS 7.)OUTPUT THE PRODUCT OF EVEN INTEGERS 8.)OUTPUT THE PRODUCT OF ODD INTEGERS SAMPLE: Vector: 2 4 3 5 2 3 8 9 1 10 Ascending...

  • Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the...

    Write a C or C++ program A8p1.c(pp) that accepts one command line string parameter. Call the fork function to produce two processes. In the child process print out the lower case version of the string. In the parent process print out the reversed upper case version of the string (e.g. child: “abc”; parent: ”CBA”). You may call the toupper and tolower functions in the header <ctype.h> if you wish. Specify in the output whether the parent or child process is...

  • Assignment: Using the Fork System Call The Collatz conjecture concerns what happens when we take any...

    Assignment: Using the Fork System Call The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorthm: n={n / 2 , if n is even 3 * n + 1 , if n is odd The conjecture states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n = 35, the sequence is:  35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4, 2,...

  • The Collatz conjecture concerns what happens when we take any positive integer n and apply the...

    The Collatz conjecture concerns what happens when we take any positive integer n and apply the following algorithm: if n is even 3 xn+1, if n is odd The conjecture states that when this algorithm is continually applied, all positive integers will eventually reach 1. For example, if n- 35, the sequence 1S 35, 106, 53, 160, 80, 40, 20, 10, 5, 16, 8, 4,2,'1 Write a C program using the fork) system call that generates this sequence in the...

  • Write a C++ program to read four whole numbers (integers) and perform the following (1) Display...

    Write a C++ program to read four whole numbers (integers) and perform the following (1) Display the largest of the numbers (2) Display the smallest of the numbers (3) Display sum of the even numbers (4) Display number of even and odd numbers

  • C program To develop a C program to implement a process system call. PROBLEM You are...

    C program To develop a C program to implement a process system call. PROBLEM You are to use the Ubuntu operating system to write a C program that creates a process to determine the identification of the current user of your computer. I mean if joe is the login of the current user of your computer your solution should return joe. Your solution must also provide the pid of both the parent and the child processes. You may use the...

  • python la ab X, X Lab 7 Design and implement a Python program that uses a...

    python la ab X, X Lab 7 Design and implement a Python program that uses a while loop and selection statements to print the sum of the even numbers and the sum of the odd numbers (all integers) read from the keyboard. The sequence of numbers ends with a negative number: So, all numbers considered for printing the two sums are greater than or equal to 0. The sequence may be empty. Here is a possible interaction. Enter an integer:...

  • Write a C++ program that asks the user to enter a single number from 1 to...

    Write a C++ program that asks the user to enter a single number from 1 to 50 and a choice of "even" or "odd". Using a recursive function, output the sum of all the even or odd integers from 1 up to (and including) that number. Your program does not need to loop and accept more input (only one input of the number then even/odd).

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT