Write loops in c code that implement the following Sum the i

Write loops in c++ code that implement the following:

Sum the integers from 0 to 20

A loop that gets an input from the user and validates that user has entered a number between 50 and 75

A loop that starts at 500 and counts down to 0 by 2 on each iteration

A loop that asks the user to input 10 numbers, computes their sum, and reports their average upon exit from the loop

dont have to have complete code just code for loops

Solution

Question: Sum the integers from 0 to 20

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

sum = sum + i;

}

Question: A loop that gets an input from the user and validates that user has entered a number between 50 and 75

while(n<50 || n >75){

cin >> n;

}

Question: A loop that starts at 500 and counts down to 0 by 2 on each iteration

for(int i=500; i>=0; i=i-2){

}

Question: A loop that asks the user to input 10 numbers, computes their sum, and reports their average upon exit from the loop

int sum = 0;

int n;

for(int i=0; i<10; i++){

cin >> n;

sum = sum + n;

}

double average = sum/(double)10;

Write loops in c++ code that implement the following: Sum the integers from 0 to 20 A loop that gets an input from the user and validates that user has entered

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site