Ask Question
14 March, 21:34

Write a function named sumNumbers that accepts a nonnegative number, adds up all of the numbers between 0 and the number (inclusive), and returns the sum.

+5
Answers (1)
  1. 15 March, 00:53
    0
    int sumNumber (int n) {

    if (n < 0)

    return 0;

    int sum = 0;

    int i;

    for (i = 0; i < = n; i++) {

    sum = sum + i;

    }

    return sum;

    }

    Explanation:

    I am going to write a C code for this.

    A for loop and an initialized variable is sufficient to solve this problem.

    int sumNumber (int n) {

    if (n < 0)

    return 0;

    int sum = 0;

    int i;

    for (i = 0; i < = n; i++) {

    sum = sum + i;

    }

    return sum;

    }
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function named sumNumbers that accepts a nonnegative number, adds up all of the numbers between 0 and the number (inclusive), and ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers