Recap Challenge #1
Part of the Fundamentals section of Coddy's C journey — lesson 42 of 63.
Challenge
EasyWrite a program that first accepts an integer n, representing how many additional whole numbers will be entered next. Then, read exactly n whole numbers from the input. Finally, compute and print the sum of those n numbers (excluding the first input).
Input:
3
1
5
6
Output:
12Explanation:
The first number 3 means that the next 3 numbers (1, 5, and 6) will be read and summed. The total is 1 + 5 + 6 = 12
Try it yourself
#include <stdio.h>
int main() {
int n, num, sum = 0;
// Read the first number (number of inputs to follow)
// Loop to read 'n' numbers and calculate the sum
// Print the result
return 0;
}All lessons in Fundamentals
3Operators
Arithmetic OperatorsModulo OperatorIncrement/DecrementAssignment OperatorsRelational OperatorsLogical Operators Part 1Logical Operators Part 2Logical Operators Part 3Recap Challenge6Loops
For LoopWhile LoopDo While LoopBreakContinueRecap Challenge #1Nested LoopsInfinite LoopsRecap Challenge #2