Question

write a c++ program to find the sum, average, highest, lowest, odd, and even numbers of...

write a c++ program to find the sum, average, highest, lowest, odd, and even numbers of a list of 10 numbers. apply arrays and functions.

==> NOTE: main program must contain only calls and declarations.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As per HomeworkLib expert answering guidelines,Experts are supposed to answer only certain number of questions/sub-parts in a post.Please raise the remaining as a new question as per HomeworkLib guidelines.
******************************************************************************************

#include <iostream>
using namespace std;
void sum(int a[], int n)
{
int s=0;
for(int i=0;i<n;i++)s+=a[i];
cout<<"Sum is "<<s<<endl;
}
void average(int a[], int n)
{
int s=0;
for(int i=0;i<n;i++)s+=a[i];
cout<<"Average is "<<(s/(double)(n))<<endl;
}
void highest(int a[], int n)
{
int ans=a[0];
for(int i=0;i<n;i++)
{
if(a[i]>ans)ans=a[i];
}
cout<<"Highest is "<<ans<<endl;
}
void lowest(int a[], int n)
{
int ans=a[0];
for(int i=0;i<n;i++)
{
if(a[i]<ans)ans=a[i];
}
cout<<"Lowest is "<<ans<<endl;
}
void odd(int a[], int n)
{
int flag=0;
for(int i=0;i<n;i++)
{
if((a[i]%2)&&(flag==0))
{
cout<<"Odd numbers is/are : "<<a[i]<<" ";
flag=1;
}
else if((a[i]%2)&&(flag!=0))
{
cout<<a[i]<<" ";
}
}
cout<<endl;
}
void even(int a[], int n)
{
int flag=0;
for(int i=0;i<n;i++)
{
if((a[i]%2==0)&&(flag==0))
{
cout<<"Even numbers is/are : "<<a[i]<<" ";
flag=1;
}
else if((a[i]%2==0)&&(flag!=0))
{
cout<<a[i]<<" ";
}
}
cout<<endl;
}

int main()
{
int a[10]={1,2,3,4,5,6,7,8,9,10};
int n = sizeof(a)/sizeof(a[0]);
sum(a,n);
average(a,n);
highest(a,n);
lowest(a,n);
odd(a,n);
even(a,n);
  
return 0;
}

Add a comment
Know the answer?
Add Answer to:
write a c++ program to find the sum, average, highest, lowest, odd, and even numbers of...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program that prompts the user to enter integers or a sentinel to stop....

    C++ Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...

  • Write a program to find the sum of all odd numbers recursively less than or equal...

    Write a program to find the sum of all odd numbers recursively less than or equal to n starting from 1, where n is any positive number. So for example n is 11 find sum of the following numbers (1,3,5,7,9,11) Write this in java please

  • Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and...

    Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. The program should output the average high, average low, and the highest and lowest temperatures for the year. Your program must consist of the following functions 1. Function getData: This function reads and stores data in the two- dimensional array. 2. Function averageHigh: This function calculates and returns the aver- age high temperature for the year. 3. Function averageLow:...

  • Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch...

    Using c++.. 1. Write a program to find the sum(), Subtraction(), Multiplication(), Division() operations using Switch statement and functions. 2. Write a program to find the summation of N numbers. Use two functions. One function will take the input from user and the other will perform the summation from 1 to N. 3. Write a program to find the factorial of a number. Use two functions. One function will take the input from user and the other will perform the...

  • Write a program with loops that compute a.The sum of all even numbers between 2 and...

    Write a program with loops that compute a.The sum of all even numbers between 2 and 100 (inclusive). b.The sum of all squares between 1 and 100 (inclusive). c.All powers of 2 from 20 up to 220. d.The sum of all odd numbers between a and b (inclusive), where a and b are inputs. Note*: For part d, enter 3 and 21 as input Output should be: a. 2550 b. 338350 c. 1.0 2.0 4.0 8.0 ... 1048576.05 d. 120

  • PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE...

    PLEASE SOLVE USING BASIC C++ CODEING PRINCIPLES PLEASE USE BASIC ARRAY, FUNCTION, AND LOOPING PRINCIPLES PLEASE COMPLETE ALL ASPECTS OF PAPER THANK YOU!!! Objectives To learn to code, compile and run a program containing ARRAYS. . Assignment Plan and code a modular program utilizing arrays. Use at least three functions to solve the problem. Input numbers from a textfile. Input the numbers, one by one. Store the even numbers in one array. Store the odd numbers in a second array....

  • C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day:...

    C Part 1 Given a structure that store the highest temperature (HighTemp) and the lowest temperature (LowTemp) of a day: typedef struct {       char DayOfMonth[31];     /*  e.g.  “May 13”,  “July 9”  */       int HighTemp;         /*  the highest temperature of that day  */       int LowTemp;         /* the lowest temperature of that day */ } DayTemp; DayTemp  Temperature[365]; Temperature is an array of structure DayTemp.  Write a function that will return the average of HighTemp for a given number of days (NumberDay)...

  • Write a complete Java program, including comments in both the main program and in each method,...

    Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once.      This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...

  • Write a program in assembly code (8088/8086) to determine the Average, Highest, Lowest grade in microprocessor...

    Write a program in assembly code (8088/8086) to determine the Average, Highest, Lowest grade in microprocessor course (final grade =100) if the class has 30 students. Write the program in the emulator(8086) and show the input data and the results (Average grade- Highest grade- Lowest Grade). Note: Suppose the grades of the 30 students.

  • write program above in C only Write a program to find statistics on some random numbers....

    write program above in C only Write a program to find statistics on some random numbers. Seed the random number generator with time. In a for loop generate 12 random numbers between the values of 2 and 20. Print the numbers. As the numbers are generated, find the following: the number of even numbers (those evenly divisible by 2) e the sum of the even numbers the product of the even numbers the maximum value of all the numbers e

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT