Question

In: Computer Science

Write a program in C++ that computes the sum of odd numbers between 1 and 117....

Write a program in C++ that computes the sum of odd numbers between 1 and 117. Execute the program and submit a screen capture of the program and its results.

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change.

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

#include<iostream>
using namespace std;

int main(){
  
   const int START = 1;
   const int END = 117;
   int totalOddSum = 0;
  
   for(int num = START; num <= END; num++){
      
       if(num%2==1) totalOddSum += num;
   }
  
   cout<<"Sum of all odd numbers between "<<START<< " and " <<END
       <<" is "<<totalOddSum<<endl;


   return 0;
}


Related Solutions

Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored...
Write an assembly program In MASM assembler to calculate the sum of odd numbers only stored in a 16-bit integers array. The size of the array is provided in a separate variable. Use the following design: Sum = 0 FOR i = 0 TO SizeOfArray - 1     IF Arr[i] % 2 = 1           Sum = Sum + Arr[i]     END IF END FOR
Q1) Write programs with iterators that computes: • The sum of all even numbers between 2...
Q1) Write programs with iterators that computes: • The sum of all even numbers between 2 and 100 (inclusive). • The sum of all squares between 1 and 100 (inclusive). • The product of all powers of 2 from 20 up to 220 . • The product of all odd numbers between a and b (inclusive), where a and b are inputs. sum would be 3 + 7 + 7 = 17.) Q2) Recall the Fibonacci sequence: 1, 1, 2,...
Write a program in C++ that generates and displays the first N three digit odd numbers....
Write a program in C++ that generates and displays the first N three digit odd numbers. Whereas the number N is provided by the user.
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
C++ CODE TO FIND ALL Odd numbers between 1 and 70000.
C++ CODE TO FIND ALL Odd numbers between 1 and 70000.
Write a JavaScript program that computes the average of a collection of numbers and then outputs...
Write a JavaScript program that computes the average of a collection of numbers and then outputs the total number of values that are greater than the average. An A grade is any score that is at least 20% greater than the average. The B grade is any score that is not an A, but is at least 10% greater than the average. An F grade is any score that is at least 20% less than the average. The D grade...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by...
JAVA Write a program to sum the numbers from 1 to 100 that are divisible by 7, and compute the average of those numbers, print both the sum and the average with appropriate messages to the screen. Run the program. Capture the console output. Put the program code and console output at the end of your text file,
Write a program that computes and prints the average of numbers in a text file. I...
Write a program that computes and prints the average of numbers in a text file. I created a text file integers.txt that has the numbers 5,4,3,2,1. I need to define the average function Define the main function which will include the following things 1. prompt user for input of text file name 2. open and read input file, can be done before or inside high order functions 3. use two high order functions 4.calculate and display averages and original ist...
Using C Language Write a program segment that computes 1 + 2 + 3 + ......
Using C Language Write a program segment that computes 1 + 2 + 3 + ... + ( n - 1) + n , where n is a data value. Follow the loop body with an if statement that compares this value to (n * (n + 1)) / 2 and displays a message that indicates whether the values are the same or different. Please give me code to just copy and paste
Write a program in C++ that prints out the even numbers between 1 and 21 using...
Write a program in C++ that prints out the even numbers between 1 and 21 using WHILE loop. Also, find the sum AND product of these numbers and display the resulting sum and product.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT