Answer:
Following are the program in c++ language
#include <iostream> // header file
using namespace std; // namespace
int main() // main method
{
int num, sum1 = 0; // variable declaration
do
{
cout << "Enter the positive number:" << endl;
cin >> num; // read number
// cout << "You are entered a negative number" << endl;
} while(num < 0);
for(int k= 1; k <= num; k++)
sum1 = sum1+k;
cout << "Sum is: " << sum1<< endl;
return 0;
}
Output :
Enter the positive number:5
Sum is: 15
Step-by-step explanation:
In this program we taking a integer input in the "num" variable from the user .
The do while loop is iterated and check the entered integer validation i.e it check whether the entered integer is positive or not .If we entered the negative integer then it again ask for entering the value .
Finally we calculated the sum of all the integers from the 1 up to the user Entered value.