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

Increased amount of carbon dioxide in the atmosphere can lead to global warming which that can lead to...
Find Tan0 where 0 is the angle shown. Give an exact value, not a decimal approximation.​
What is the temperature of the star in the illustration?
In what ways are products of fractions similar to products of integers?
Which equation represents a proportional relationship that has a constant of proportionality equal to -10
Find the mass, in grams, of 20.0 L of N2 at STP
out of 90 candies 30% are chocolate candies. how many candies are chocolate candies
30) When ionic bonds are formed, metallic atoms tend to A) lose electrons and become negative ions B) lose electrons and become positive ions C) gain electrons
What is the velosity of a 72.3 kg jogger with a kinetic energy of 1080.0 J?
The physical implications of long-term, heavy use of alcohol?