Design a program that displays the sum of the integer numeric values stored in t
ID: 3682646 • Letter: D
Question
Design a program that displays the sum of the integer numeric values stored in two arrays, in a tabular format. The design defines two arrays of the same size (each array has 10 dements). One array stores odd integer numeric values (the first clement of the array (at index 0) stores the value 1,... etc). An other array stores even integer numeric values (the first clement of the array (at index 0) stores the value 2, ..., etc). Program Requirements: The program displays a title (appropriate for the case being solved). The program displays on a single line three headings (i.e., labels) - to identify the corresponding odd, even, and sum values. The program displays the triplets (i.e., the three numeric values - odd, even, and sum), one triplet per line of output, for a total of 10 output lines. The indices of the arrays are zero-based. The arrays are dimensioned to contain 10 elements (not 11 eleven elements) Expected Submittals: The Visual Logic program (50%). Formal pseudocode, pseudocode must follow the flow of your application, and flowchart (following the book syntax, proper indentation, with variable declarations, and start, stop, and returns as needed, etc.). Use Notepad++ to create the pseudocode (*.txt file) (20%). Formal flowchart of the application (following the book syntax, proper symbols, must follow the flow of your application, and pseudocode, must be saved as either a *.jpg or *.png file) (20%). Files submitted should be named as follows: (10%) Lab5_lastname_program.vls Lab5_lastname_pseudocodc.txt Lab5_lastname_flowchart.jpgExplanation / Answer
int pfork(int);
void process_join(int,int);
#include<sys/types.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<stdio.h>
int main()
{
int sum=0,fsum;
int *a3,shmid,id;
int i,n,a1[10],a2[10];
printf("enter how many nos ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("enter odd number for 1st array: ");
scanf("%d",&a1[i]%2!=0);
}
for(i=0;i<n;i++)
{
printf("enter even number for 2nd array: ");
scanf("%d",&a2[i]%2==0);
}
shmid=shmget(IPC_PRIVATE,4,0666|IPC_CREAT);
a3=(int *)shmat(shmid,0,0);
if(shmid < 0)
{
printf("Error ");
}
for(i=0;i<n;i++)
{
*(a3+i)=0;
}
id=pfork(2);
if(id==0)
{
for(i=0;i<n;i+=2)
{
*(a3+i)=a1[i]+a2[i];
}
printf("parent doing sum ");
for(i=0;i<n;i+=2)
{
printf("sum by parent %d ",*(a3+i));
}
printf(" ");
}
else
{
if(id==1)
{
for(i=1;i<n;i+=2)
{
*(a3+i)=a1[i]+a2[i];
}
printf("child doing sum ");
for(i=1;i<n;i+=2)
{
printf("Sum by child %d ",*(a3+i));
}
printf(" ");
}
}
//printf("Calling process join for id %d ",id);
process_join(2,id);
printf("The final sum array is : ");
for(i=0;i<n;i++)
{
printf(" %d ",*(a3+i));
}
printf(" ");
printf("End Parent ");
return 1;
}
int pfork(int x)
{
int j;
for(j=1;j<=(x-1);j++)
{
if((fork())==0)
return j;
}
return 0;
}
void process_join(int x,int id)
{
int j,val;
if(id==0)
{
for(j=1;j<=(x-1);j++)
{
printf("parent process id %d ",getpid());
printf("Parent calling wait:blocked state ");
val=wait(0);
printf("The child deleted is : %d ",val);
}
}
else
{
printf("child pid %d ",getpid());
exit(0);
}
printf("after exit %d ",getpid());
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.