Question

In: Computer Science

Input 10 integers and display the following: a. the sum of even numbers. b. the sum...

Input 10 integers and display the following:

a. the sum of even numbers.
b. the sum of odd numbers.
c. the largest integer
d. the smallest integer
e. the total count of even numbers
f. the total count of odd numbers.

Using C++ program with for loop..

Solutions

Expert Solution

#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
int arr[10];
int i,oddSum=0,evenSum=0,countodd=0,counteven=0,max,min;
cout<<"enter the values";//enter 10 integers
for (i = 0; i < 10; i++)
cin >> arr[i];
max = arr[0];
for (i = 0; i < 10; i++)//find largest number
{
if (max < arr[i])
max = arr[i];
}
min = arr[0];
for (i = 0; i < 10; i++)//find smallest number
{
if (min > arr[i])
min = arr[i];
}
cout << "Largest element : " << max;
cout << "Smallest element : " << min;

for(i=0; i<10; i++)//sum and count of even and odd numbers
{
if(arr[i]%2==0)
{
evenSum=evenSum+arr[i];
counteven++;
}
else
{
oddSum=oddSum+arr[i];
countodd++;
}
}

cout<<"The sum of odd numbers are:"<<oddSum;
cout<<"\nThe sum of even numbers are:"<<evenSum;
cout<<"\nThe count of odd numbers are:"<<countodd;
cout<<"\nThe count of even numbers are:"<<counteven;
getch();
return 0;
}


Related Solutions

The sum of two integers is 54 and their different is 10. Find the integers
The sum of two integers is 54 and their different is 10. Find the integers
Write a loop for each of the following: The sum of all even numbers between 2...
Write a loop for each of the following: The sum of all even numbers between 2 and 100 (inclusive). The sum of all squares between 1 and 100 (inclusive). (If you use the pow function the first parameter must be a float or double). The sum of all odd numbers between a and b (inclusive). Where a and b are read in by the user. How often do the following loops execute? Assume that i is not changed in the...
Write an algorithm (flowchart) for the following problems: Take ten different numbers as input and display...
Write an algorithm (flowchart) for the following problems: Take ten different numbers as input and display the sum of there squares (SS). Example: let the inputs are: 3, 0, -1, 0, 9, -5, 6, 0, 2, 1 then 157 is displayed, because: SS=32+02+(-1)2+02+92+(-5)2+62+02+22+12=157
Sum of numbers between 1 and 10
Calculate the values from the  smallest number to the largest number
Write assembly instructions that compute the following: The sum of all even numbers between 2 and...
Write assembly instructions that compute the following: The sum of all even numbers between 2 and 100 (inclusive) -- the answer should be 2550 Prompt the user for 2 values, put them in variables a and b, then find the sum of all odd numbers between a and b. The sum of all the squares between 1 and 100 (inclusive) . -- the answer should be 338350 All of the statements above should print the answers using print_int MUST BE...
The following table shows pairs of hexadecimal numbers A and B. What is the sum of...
The following table shows pairs of hexadecimal numbers A and B. What is the sum of A and B if they represent unsigned 16-bit hexadecimal numbers? The result should be written in hexadecimal. Show your work A 0D34 DD17 B BA1D 3617
Make a function that calculates the summation of even numbers in the range. The function sum...
Make a function that calculates the summation of even numbers in the range. The function sum takes the two integer parameters and they are used as the range. The function uses default parameters for the range. When we call this function with one argument, it will be used as a starting point and the end of the range will be 100. Also, the function is called without any argument, the default range (0,100) will be used. We will use default...
Create a program that asks the user to input three numbers and computes their sum. This...
Create a program that asks the user to input three numbers and computes their sum. This sounds simple, but there's a constraint. You should only use two variables and use combined statements. You can use the output below as a guide. Please enter the first number: 4 Please enter the second number: 2 Please enter the third number: 9 The sum of the three numbers is: 15.
Input from console 3 double numbers, compare these 3 numbers and display them from small to...
Input from console 3 double numbers, compare these 3 numbers and display them from small to great. In Java Please
How many eight-digit positive integers have the sum of digits being even?
How many eight-digit positive integers have the sum of digits being even?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT