Answer to Question #300337 in C++ for Hazel Mendoza

Question #300337

Write a program that will get the average of all integers from 1 to 20 using do while loop.


1
Expert's answer
2022-02-20T09:59:54-0500




#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog