Ask Question

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.

+2
Answers (1)
  1. 9 December, 04:27
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers