answersLogoWhite

0

Use the following functions:

int sum (const int* const a, const unsigned size) {

int s = 0;

for (unsigned i=0; i<size; ++i) s += a[i];

return s;

}

double average (const int* const a, const unsigned size) {

return (double) sum (a, size) / size;

}

Example usage:

int main () {

int[3] a = {74, 42, 64};

printf ("Sum = %d\n", sum (a, 3)); // Sum = 180

printf ("Average = %d\n", average (a, 3)); // Average = 60.0

return 0;

}

User Avatar

Wiki User

8y ago

What else can I help you with?

Related Questions

Make a C programming that displays the first four perfect numbers?

create a program that iterates until it finds a perfect number, then store that perfect number into an array. Continue iterating until you find three more. Then, you have an array of four perfect numbers.


Write the program in qbasic and add two numbers?

Cls input "enter two no.s ",a,b sum=a+b print "sum = ";sum end


Pseudocode representation to determine the average of three numbers?

#include &lt;iostream&gt;02using namespace std; 03 04int main() 05{ 06 int sum = 0; 07 int average = 0; 08 int array[10] = {1,2,3,4,5,6,7,8,9,10}; 09 for (int i = 0; i &lt; 10; ++i) 10 sum+=array[i]; 11 average = sum/10; 12 cout&lt;&lt;"Average:"&lt;&lt;average; 13}


Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


What is the average of 5000 and 7000?

To calculate the average of two numbers, add them together, and divide the result by 2. (For the average of three numbers, you add up the three numbers, and divide by three, etc.) The average is (5000 + 7000)/2 = 6000


What are the three numbers if the average of three consecutive numbers is 126?

125, 126 and 127.


Could an average of three numbers be one of those three numbers?

Yes. For example, the average of 5, 7, and 9 is 7.


What are three prime numbers where the average is a prime number?

3, 5, and 7 are three prime numbers whose average is 5.


What is the average of 51 52 on 56?

The average of the numbers 51, 52, and 56 is 53. To get the average you would add all three numbers and then divide by three.


The average of the first three numbers was sixThe average of the next seven numbers was 19 What was the overall average of all 10 numbers?

12


What is the average number of publications for PhD candidates in your program?

The average number of publications for PhD candidates in our program is three.


What are three prime numbers where the average is also a prime number?

3, 5, and 7 are three prime numbers whose average is 5.