Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

// Finish the following program which adds up all integers from 0 to the user\'s

ID: 3921809 • Letter: #

Question

// Finish the following program which adds up all integers from 0 to the user's given number inclusively using a FOR loop. The total should be assigned to the variable 'total'.

#include <iostream>

using namespace std;

int main()

{

int number;

int total;

cout << "Enter a positive integer to find the summation of"

<< " all numbers from 0 to the given number." << endl;

cin >> number;

// TODO - Add your code here

cout << "Total : " << total << endl;

return 0;

}

for c++ Programming

Explanation / Answer

Solution.cpp

#include <iostream>//header file for input output function

using namespace std;//std namespace

int main()

{//main function

int number;//variable declaration

int total=0;

cout << "Enter a positive integer to find the summation of"<< " all numbers from 0 to the given number.    ";

cin >> number;

// TODO - Add your code here

for(int i=0;i<=number;i++)//for loop
total=total+i;
cout << "Total : " << total << endl;

return 0;

}

output

Enter a positive integer to find the summation of all numbers from 0 to the given number. 5

Total : 15