Answer to Question #301188 in C++ for Chubby

Question #301188

Make a C++ program that will input a number and display the sum of the numbers from 1 to the input number using do while loop.


1
Expert's answer
2022-02-22T12:13:35-0500
#include <iostream>
using namespace std;

int main() {
    int num;
    cout << "Enter a number: ";
    cin >> num;

    int sum = 0;
    int i = 1;
    
    do {
        sum += i;
        i++;
    } while(i <= num);

    cout << "The summ is " << sum;

    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