Wednesday, 16 November 2016

Write a C++ program to find the largest , smallest and average of n whole numbers.



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();
        }    

4 comments:

If you have any doubt please let me know

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...