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 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...
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?
Question 1: Write a program to receive two integers as user input and then print: Sum...
Question 1: Write a program to receive two integers as user input and then print: Sum Difference Product Average Maximum of the two Minimum of the two You may use the min and max functions declared in the math class. ********************************************************************************** Question 2: An online bank wants you to create a program that will show a prospective customer, how the deposit will grow. Your program should read the initial balance and the annual interest rate. Interest rate is compounded monthly....
Two numbers a and b are called pythagorean pair if both a and b are integers...
Two numbers a and b are called pythagorean pair if both a and b are integers and there exists an integer c such that a2 + b2 = c2. Write a function pythagorean_pair(a,b) that takes two integers a and b as input and returns True if a and b are pythagorean pair and False otherwise.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT