Sum of a Sequence of Numbers (more generic)
Writing a program that always computes the same output has very limited
utility. Based on your special_sequence_sum.c program
write a new program that allows users to enter the lower limit (inclusive)
and the upper limit (exclusive) of a sequence of numbers to be summed.
Users also have to be able enter a number in case they only want every
second / third / fourth / ... number to be summed up.
That number has to default to 1.
Print the result to
stdout
.
Once you have a working solution, consider if there is a better solution.
A sample run of this program:
This programs computes the sum of a sequence of numbers.
Enter the lower limit (inclusive): 123
Enter the upper limit (exclusive): 456
Only sum every nth number [default: 1 (every number)]: 100
The desired sum is 1092.
Note that 1092 is the sum of 123 + 223 + 323 + 423.
Name the source file: sequence_sum.c