Write a program that will get the average of all integers from 1 to 20 using do while loop.
#include <iostream>
#include <iomanip>
#include <math.h>
using namespace std;
int main()
{
float sum=0;
int i=1;
int counter=0;
do {
sum+=i;
counter++;
i++;
} while (i<=20);
cout<<"The average of all integers from 1 to 20: "<<(sum/(float)counter)<<"\n\n";
system("pause");
return 0;
}
Comments
Leave a comment