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
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)
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
hw1) Write a python script using for loop, which calculates the sum of the squares of...
hw1) Write a python script using for loop, which calculates the sum of the squares of the numbers from 5 to 23. (i.e. 52+62+72+ ... +222+232) hw2) try to calculate the same in hw1 using the while loop instead of for loop.
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 program in C that does the following: Reads 10 real numbers from the keyboard...
Write a program in C that does the following: Reads 10 real numbers from the keyboard using a loop and displays the sum of the numbers and the sum of the square of the numbers.
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT