Question #35545

create a dev c++ that will compute the average from 1 to n
1

Expert's answer

2013-09-30T11:00:53-0400
#include <iostream>
using namespace std;
int main()
{
    int n = 0, sum = 0;
    double av = 0;
    do
    {
        cout << "Enter n = ";
        cin >> n;
    }
    while (n <= 0);
    for (int i = 1; i <= n; i++)
    {
        sum += i;
    }
    av = double(sum) / n;
    cout << "Average = " << av;
    cin.ignore(256, '\n');
    cin.get();
}

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!
LATEST TUTORIALS
APPROVED BY CLIENTS