C++ Programming help

后端 未结 5 454
甜味超标
甜味超标 2021-01-29 06:38

You create a program that displays the sum of even integers between and including two numbers entered by the user ..

ex) 2 and 7 = the sum of 12 (2+4+6)

this is

5条回答
  •  一生所求
    2021-01-29 07:31

    In your for loop it should be like this.

    double sum = 0.0;
    for(i = num1; i <= num2; i++){
    if(i % 2 == 0){  // Is our number even
       sum += i;
      }
    }
    

    That's it and it print out sum.

提交回复
热议问题