Question

Write a loop that generate even numbers such as 2,4,6, ....., 18, 20. sum those numbers...

Write a loop that generate even numbers such as 2,4,6, ....., 18, 20.

sum those numbers

using c++

Homework Answers

Answer #1

#include <iostream>

using namespace std;

int main(){

int sum=0;

for(int i=2;i<=20;i=i+2){

sum=sum+i;

cout<<i<<" ";

}cout<<endl;

cout<<"Sum: "<<sum<<endl;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python code Write a complete program with for loop which calculates the sum of the numbers...
Python code Write a complete program with for loop which calculates the sum of the numbers from 1 to 100
Please, write a loop to print even numbers of an array a with pointers. You can...
Please, write a loop to print even numbers of an array a with pointers. You can use a variable “size” for array size
Write a function that takes two integer inputs and returns the sum of all even numbers...
Write a function that takes two integer inputs and returns the sum of all even numbers between these inputs, and another function that takes two integer inputs and returns the sum of odd numbers between these inputs .In main function, the program will asks the user to enter two integer numbers and then passes them to these two functions and display the result of each of them.         [0.5 mark] (BY USING C PROGRAM)
write a java program to find the sum of natural numbers from 1 to 1000 inclusive...
write a java program to find the sum of natural numbers from 1 to 1000 inclusive (using for loop) sample output: sum=500500
1) Use a loop structure to calculate the sum of all odd numbers from 1 to...
1) Use a loop structure to calculate the sum of all odd numbers from 1 to 15 2) Use a loop structure to calculate the product of all odd numbers from 1 to 9. 3) Write a program to convert US dollars to Bangaldeshi taka
write a main module that includes a loop that will loop 5 times. With each iteration,...
write a main module that includes a loop that will loop 5 times. With each iteration, ask the user for a number, and accumulate the sum. After the loop, print the sum of the numbers.
Write a nested FOR loop (using two for loops & two fprintf statements to generate the...
Write a nested FOR loop (using two for loops & two fprintf statements to generate the following pattern: ***** **** *** ** *
Write a Python program using while loop that finds and prints the sum of this geometric...
Write a Python program using while loop that finds and prints the sum of this geometric series. 1 + 2 +4 +8 + … + 1024
1- Write a program to print only the even numbers from 100 to 200 2- Write...
1- Write a program to print only the even numbers from 100 to 200 2- Write a program to print the odd numbers from 22 – 99 3- Write a program to calculate howe many even number from 10 to 120 1- Write a program to find only the even numbers for 12 different numbers 2- Write a program to find the odd numbers for 10 different numbers 3- Write a program to calculate howe many even number and how...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...