Write a program to find the largest , smallest and average of n whole numbers. You can assume that "n" has already been set by the user.
Solution :
#include <iostream.h>
#include <conio.h>
int main ()
{
clrscr();
int largest , smallest , value ;
int n = 10;
float total;
cout<< "Please enter a whole number : " ;
cin>> vlaue;
largest = smallest = total = value;
for (int j= 0; j <= n-1; ++j)
{
cout<< "Please enter a whole number: ";
cin>> value;
total += value;
if (value > largest)
largest = value;
if (value < smallest)
smallest = value;
}
cout<< "The largest value is: "<< largest << endl;
cout<< "The smallest value is: "<< smallest<<endl;
cout<< "The average is: "<< total/n << endl;
getch();
}
C++ Programming Exercises
ReplyDeleteit was error
ReplyDeleteis there a way to do it with unlimited entries by user.
ReplyDeleteyes use while loop as:
Deletewhile (1)
{
code body
}