#WSQ7-Sum of numbers

This code was easy as I remember!! Also just a little of research in formulas to be able to complete it.

I wrote a program that asks for a range of integers and then prints the sum of the numbers in that range (inclusive).

I did use a formula to calculate this of course but what we want you to do here is practice using a loop to do repetitive work.

x=(n*(n+1))/2;

For example, the sum from 6 to 10 would be 0 + 6 + 7 + 8 + 9 + 10.

//CODE:

#include <iostream>

using namespace std;

void sumofnumbers(int n) {
int R=0;
R=(n*(n+1))/2;
std::cout << “The sum of the range is… “<<R << std::endl;
}

int main(int argc, char const *argv[]) {
int n, R;
std::cout << “This program sum the rage of numbers from the enter one.” << std::endl;
std::cout << “Please enter a number to sum its range.” << std::endl;
std::cin >> n;
sumofnumbers(n);

return 0;
}

Captura de pantalla 2016-02-17 a las 18.46.37

CC BY-SA 4.0 #WSQ7-Sum of numbers by everolivares is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.