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