Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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]max){ max=values[i]; } total=total+values[i]; } average=total/n;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Big Data, Mining, And Analytics Components Of Strategic Decision Making

Authors: Stephan Kudyba

1st Edition

1466568704, 9781466568709

More Books

Students also viewed these Databases questions

Question

2. KMPG LLP

Answered: 1 week ago

Question

5. Wyeth Pharmaceuticals

Answered: 1 week ago