Write C++ program to Find Min, Max and Average
Dear Students, Today in C++ Programming Tutorial we will learn How to write C++ program to Find Minimum , Maximum and Average. It is a Simple c++ program which takes input numbers from user and will find minimum, maximum and average of numbers.How to write C++ program to Find Min, Max and Average |
In this Program we will uses do while loop to find min, max and avg. User can input many numbers. To calculate user has to break do while loop condition which breaks when user inputs -1
C++ Program Code:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
float max=0.0,min=0.0,sum=0.0;
float num=0.0;
float avg=0.0;
cout<<"enter a whole number or -1 to get result:"; //program working through example
cin>>num;
max=num;
min=num;
do
{
if(num!=-1){
sum=sum+num;
if(num>max)
max=num;
else
if(num<min)
min=num;
cout<<"enter a whole number or -1 to get result:";
cin>>num;
}
}
while(num!=-1);
avg=sum/10.0;
cout<<"sum="<<sum<<endl;
cout<<"average of numbers you entered is:"<<avg<<endl;
cout<<"maximum number you enter is:"<<max<<endl;
cout<<"minimum number you enter is:"<<min<<endl;
getch();
}
Sample output of C++ Program
sample output of C++ program to Find Min, Max and Average |
Have a Look on More C++ Example Programs:
- Write ALLAH Using C++ Program
- How to write C++ program to find Fibonacci Series
- How to Write C++ Program to Find Prime Number
- How to write C++ Program to find factorial of Number
- How To Write C++ Program To Make A Simple Snake Game
If you liked this C++ Tutorial Please Share with Your friends and Like us on facebook. Thank You
Post a Comment