Write a program that will get the average of all integers from 1 to 20 using do-while loop.
#include <iostream>
#define SIZE 20
int main()
{
int sum=0;
double avg=0;
int i = 0;
do
{
sum += i;
std::cout<<i<<std::endl;
i++;
} while (i <= SIZE);
avg = ((double)sum / (double)SIZE);
std::cout << "Average of all integers from 1 to 20 : " << avg << std::endl;
return 0;
}
Comments
Leave a comment