Sail E0 Webinar
Question


What is the output of this program?


1.
#include
2.
#include
3.
using namespace std;
4.
float avg( int Count, ... )
5.
{
6.
va_list Numbers;
7.
va_start(Numbers, Count);
8.
int Sum = 0;
9.
for (int i = 0; i < Count; ++i )
10.
Sum += va_arg(Numbers, int);
11.
va_end(Numbers);
12.
return (Sum/Count);
13.
}
14.
int main()
15.
{
16.
float Average = avg(10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
17.
cout
Options:
A .  4
B .  5
C .  6
D .  7
Answer: Option A

We are just calculating the average of these numbers using cstdarg.
Output:
$ g++ uka.cpp
$ a.out
Average of first 10 whole numbers 4



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers