number 2 33558 1. Write a program using a for loop that read 10 numbers form the
ID: 3911761 • Letter: N
Question
number 2
33558 1. Write a program using a for loop that read 10 numbers form the keyboard and find their sum. Write a function called average which returns the average base on the sum of the 10 numbers. (30 points) 2. Write a function called test_number which reads a number (num1) between 1 and 10. If the value is 10, square numl. If the value is 9, read a new value into numl. If inputed value is no print out the result. Implement point) t (9 Or 10) multiply numl by 99 and your code using if statements only. (30 3. What will be printed for the following program segment given x 4, y 0 and z = 2: (15 points)Explanation / Answer
Answer is as follows :
The function for question 2 is as follows :
#include <iostream>
using namespace std;
void test_number(int num1)
{
if(num1 <= 10 && num1 >= 1) // check number is between 1 and 10
{
if (num1 == 10) // if number is 10
{
num1 = num1*num1; // calculate square
cout << num1 ; // print result
}
else if(num1 == 9) // if number is 9
{
cin >> num1; // input new number
cout << num1; // cout number
}
else
{
num1 = num1*99; // for other numbers
cout << num1; // print result
}
}
else
{
cout << "enter number between 1 and 10" ; // if number is not b/w 1 and 10
}
}
int main()
{
int a;
cout << "Provide input a " ;
cin >> a;
test_number(a);
return 0;
}
// are comments....
We are provide only statements, not full code, if you want that let us know in comments....
if there is any query please ask in comments...
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.