Question
C programing: I tried to find the average, minimum and maximum for an array. But the average and minimum is incorrect. Can you please fix
C programing: I tried to find the average, minimum and maximum for an array. But the average and minimum is incorrect. Can you please fix the code?
#include
int main(int argc, char **argv) {
double values[10]; int i; double average = 0; int min, max; int numvalues = argc-1;
if (numvalues > 10) { printf("Too many values "); exit(-1); }
for (i=1; i max=min=values[0]; int total=0; int n=sizeof(values)/sizeof(values[0]); for(i=1; i<=n; i++) { if(values[i] printf("Average is %d ", average); printf("Minimum is %d ", min); printf("Maximum is %d ", max); } output: ./stats 4 5 6 Average is 1 Minimum is 0 Maximum is 6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started