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
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...
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....
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?
Please use C++ 1. A Sequence of numbers and a sum is given as input. List...
Please use C++ 1. A Sequence of numbers and a sum is given as input. List all combinations of numbers that can add upto the given Sum. User input:- Enter numbers: -   1, 3,7,9,11 Enter a sum :- 20 Output: 11+9 = 20 1+3+7+9 = 20 2. Print absolute prime numbers between a given range:- Enter Range - 2,99 For eg Prime numbers are:- Prime numbers ==> 2,3,5,7,11,13,17,19,23 Absolute Prime numbers ==> 2,3,5,7,11,23 3. Write an encoder and decoder program,...
use Python The assertion that every even number is the sum of two prime numbers is...
use Python The assertion that every even number is the sum of two prime numbers is called Goldbach’s conjecture. You will write a program that asks the user for an integer number, then checks if the integer is even, and finally determines two prime numbers that sum to the user’s entered integer number. Assignment Requirements Three functions are required: get_input(): This function takes no parameters, but will ask the user for an integer number. It will return a valid integer....
Write a loop that will calculate the sum of all even numbers from 2 to 30...
Write a loop that will calculate the sum of all even numbers from 2 to 30 ( including 30) store the result in the variable called thirtySum. Declare and initialize all variables. Answer using programming in c.
Three positive integers (a, b, c) with a<b<c are called a Pythagorean triple if the sum...
Three positive integers (a, b, c) with a<b<c are called a Pythagorean triple if the sum of the square of a and the square of b is equal to the square of c. Write a program that prints all Pythagorean triples (one in a line) with a, b, and c all smaller than 1000, as well the total number of such triples in the end. Arrays are not allowed to appear in your code. Hint: user nested loops (Can you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT