Sum of n numbers( n is entered by user).

 #include <iostream>

#include <cstdlib>

#include <ctime>


using namespace std;


int main()

{

    int x = 1, n, number, total;


    total = 0;

    cout << "Enter how many numbers you want to add: " << endl;

    cin >> n;


    for(x; x<=n; x++){ //Important

        cout << "Enter " << x << " number: " << endl;

        cin >> number;

        total = total + number;

    }


    cout << total << endl;

    return 0;

}


Comments

Popular posts from this blog

Hackerearth Pr1.

Avg age of any no. of ppl for loop

Random Number