UP | HOME

Exercise 6

sum of the first n positive integers

Write a program that computes the sum of the first \(n\) positive integers, where \(n\) is specified by the user. Let's assume for now that \(n>0\) and \(n<500\). Test it on \(n=5\), \(n=50\) and \(n=500\), the output should be:

the sum of the first 5 positive integers is: 15
the sum of the first 50 positive integers is: 1275
the sum of the first 500 positive integers is: 125250

solutions


Paul Gribble | fall 2014
This work is licensed under a Creative Commons Attribution 4.0 International License
Creative Commons License