luscious2872 luscious2872
  • 06-02-2020
  • Computers and Technology
contestada

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.

Respuesta :

joaobezerra joaobezerra
  • 06-02-2020

Answer:

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;

}

Answer Link

Otras preguntas

ANSWER PLZ QUICK AND FAST
what is the sum of 3 consecutive odd numbers is 69 what is the third number in the sequence
The financial statement that shows business results in terms of revenue and expenses is __________. : an income statement a balance sheet a statement of ow
ACT help? The graph of a linear function has slope -2/3 and passes through the point (2,1). Which of the following points is on the graph of the function? a) (-
PLS HURRY use the graph to answer the question. Which table of ordered pairs shows a proportional relationship? x 1 12 y 2 6 x 5 12 y 10 6 x 5 8 y 10 4 x 3
Simplify each difference. (5n^2 + 7n) - (7n^2 + 8n )
5.98 x 15.2 w/ work thanks
Why did the Soviet Union want to create a 'buffer' zone between themselves and Western Europe? To protect themselves from potential military invasion To protec
3(x -2) = 12 how to solve and what's the answer ?
I need help on a and b