1. Write a program that calculates and prints the average of several integers. A
ID: 3544675 • Letter: 1
Question
1. Write a program that calculates and prints the average of several integers. Assume the last value read with scanf is the sentinel 9999. A typical input sequence might be
10 8 11 7 9 9999
Indicating that the average of all the values preceding 9999 is to be calculated.
2. Write a function integerPower ( base, exponent) that returns the value of
base^(exponent)
For example, integerPower ( 3,4) = 3*3*3*3. Assume that exponent is a positive, nonzero
integer, and base is an integer. Function integerPower should use
Explanation / Answer
1 // Exercise 2.41 Solution 2 #include 3 4 using std::cout; 5 using std::endl; 6 using std::cin; 7 8 int main() 9 { 10 int value, count = 0, total = 0; 11 12 cout > value; 14 15 while ( value != 9999 ) { 16 total += value; 17 ++count; 18 cout > value; 20 } 21 22 if ( count != 0 ) 23 coutRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.