Problem Specification You are asked to write a C program that reads contents of
ID: 3818385 • Letter: P
Question
Problem Specification You are asked to write a C program that reads contents of an input buffer, processes the read data, and stores the results in an output buffer. Each of actions is these performed by a different function. Additionally, this m should also generate data and put it in the input buffer (you are simulating a process of filling out an input buffer with data) In reality, a program you are about to write runs in an infinite loop constantly checking, processing, and outputting data. However, to make it simpler and doable the user will control how many loops of reading an input buffer should execute, i.e., the program should ask the user after each loop if he/she wants to continue A very simple flowchart of the program is shown besides. Pre-lab task: l. Develop a detailed flowchart using this one as a starting point. 2. Execute (manually) the algorithm. Please submit the PRE LAB Cpdf file) with the results of the task 2 (execution of the algorithm) using eClass. The deadline is the noon of the lab day of your section (e.g., for Section H32, the deadline is Mar st 12:00PM). YES set up: input buffer output buffer generate data points read data from input buffer perform one of four processing functions write results to output buffer more cycles NO STOPExplanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int max_length=10;
float input[]={0,0,0,0,0,0,0,0,0,0,0,0};
float output[4]={0,0,0,0};
float local[4]={0,0,0,0};
float* min(float*,float*,int);
float* max(float*,float*,int);
float* avg(float*,float*,int);
float* minmaxavg(float*,float*,int);
int main()
{
int id,no_of_data_points,i,j,k;
while(1){
printf("Enter the ID of the function to perform: ");
scanf("%d",&id);
printf("Enter number of data points: ");
scanf("%d",&no_of_data_points);
for(i=2;i<no_of_data_points;i++)
{
input[i]=rand();
}
input[0]=id;
input[1]=no_of_data_points;
if(input[0]==1)
output=min(input,local,no_of_data_points);
else if(input[0]==2)
output=max(input,local,no_of_data_points);
else if(input[0]==3)
output=avg(input,local,no_of_data_points);
else
output=minmaxavg(input,local,no_of_data_points);
printf("Output: ");
for(i=0;i<4;i++)
printf(" %f",output[i]);
printf("To continue press 1 To exit press 2");
scanf("%d",&j);
if(j==2)
break;
}
return 0;
}
float* min(int* a,int* b,int fp)
{
float min=a[0],i;
for(i=0;i<fp;i++)
if(a[i]<min)
min=a[i];
b[1]=min;
b[0]=1;
return b;
}
float* max(float* a,float* b,int fp)
{
float max=a[0],i;
for(i=0;i<fp;i++)
if(a[i]>max)
max=a[i];
b[1]=max;
b[0]=2;
return b;
}
float* min(float* a,float* b,int fp)
{
int sum=0,i;
for(i=0;i<fp;i++)
sum=sum+a[i];
b[1]=sum/fp;
b[0]=3;
return b;
}
float* minmaxavg(float* a,float* b,int fp)
{
float min=a[0],i;
for(i=0;i<fp;i++)
if(a[i]<min)
min=a[i];
b[1]=min;
float max=a[0];
for(i=0;i<fp;i++)
if(a[i]>max)
min=a[i];
b[2]=max;
b[0]=4;
float sum=0;
for(i=0;i<fp;i++)
sum=sum+a[i];
b[3]=sum/fp;
return b;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.