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...
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....
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT