Menu
Coddy logo textTech

Recap Challenge #1

Part of the Fundamentals section of Coddy's C journey — lesson 42 of 63.

challenge icon

Challenge

Easy

Write 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:
12

Explanation:

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