Answer to Question #298810 in C++ for Princess faith Ner

Question #298810

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-17T05:20:45-0500
#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;
}

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