Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We want to write a program that adds all the odd numbers between 1 and a user gi

ID: 3691721 • Letter: W

Question

We want to write a program that adds all the odd numbers between 1 and a user given value that is greater than 1. For example, if the user enters 3, then the program computes the sum 1+3 and outputs 4. if the user enters 6. then the program computes the sum 1+3+5 and outputs 9, etc. Fill in the missing part of the following program to solve this problem. #include using namespace std; int main() { int i, n, sum; cout muchlessthan "Enter the input value (must be greater than 1): "; cin muchgreaterthan n; /* write the missing part below */ cout muchlessthan "The sum is: " muchlessthan sum muchlessthan endl; return 0; }

Explanation / Answer

# include <stdio.h>

# include <iostream>

using namespace std;

int main() {

int i, n,sum=0;

cout << ."Enter the input value (must be grater than 1) :";

cin >> n;

for(i=1; i<=n; i++)

if(i%2 !=0)

sum=sum+i;

cout << "The sum is : " << sum<< end1;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote