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.
#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;
}
Comments
Leave a comment