Ask Question
11 August, 13:22

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.

+4
Answers (1)
  1. 11 August, 15:22
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers