Write and test a C program that lets a user interactively manipulate an array (A
ID: 3870988 • Letter: W
Question
Write and test a C program that lets a user interactively manipulate an array (A) holding 49 integers Commands to the program are integers that should be interpreted as follows 0 Quit the program 1. Fill A with zeroes 2. Generate 49 random integers and store in A. Each integer is greater than 3. 4. 5. or equal to 0 and less than 10. See Program 1 for information about random number generation Output the contents of A, 7 numbers to a line Display the contents of A as a histogram (see example program run) Report the mean, median and standard deviation of contents of A add the following command 6. Report the length and location of the longest sequence of identical integers. (If there are two or more longest sequences, identify the first one.)Explanation / Answer
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
int main() {
int m=0,k=0,j=0,n,i,c=0,p,A[49]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49};
float sv=0,svv;
printf("Print value of n: ");
scanf ("%d",&n);
switch(n){
case 1:
break;
case 2:
for(i=0;i<49;i++)
{A[i]=0;
printf("%d",A[i]);
}
break;
case 3:
for(i=0;i<49;i++)
{A[i]= rand()%10;
printf("%d",A[i]);
}
break;
case 4:
for(i=0;i<49;i++)
{c=c+1;
p=c%7;
printf("%d ",A[i]);
if(p==0)
{printf(" ");}
}
break;
case 5:
for(i=0;i<49;i++)
{
printf("%9d%15d ", i, A[i]);
for(j = 1; j<= A[i]; j++)
printf("*");
printf(" ");
}
break;
case 6:
for(i=0;i<49;i++)
{j=j+A[i];}
k=j/29;
printf("Mean of all elements = %.2d ", k);
float temp;
for(i=48;i>=0;i--)
{for(j=0;j<=i;j++)
if(A[j]>=A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
} }
m=A[24];
printf("Median of all elements = %.2d ", m);
for (i = 0; i <49; i++)
{
sv = sv + pow((A[i] - k), 2);
}
svv = sqrt(sv);
printf("Standard deviation = %.2f ", svv);
break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.