Subscribe For Free Updates!

We'll not spam mate! We promise.

Sunday 20 November 2016

C++ Q&A

QN. 1 Write a program that will accept up to 10 integers. The program compares the numbers to determine which is maximum and which one is minimum. At the end the program outputs the minimum number entered and maximum number entered.

ANSWER
#include<iostream.h>
#include<conio.h>

void main(){
    int n;
    double num;
    double max=0.00;
    double min=999999.00;
    double Maximum(double num,double max);
    double Minimum(double num,double min);
     cout<<"How many numbers do you want to compare?"<<endl;
     cin>>n;
    cout<<"Please Enter "<<n<<" numbers"<<endl;
     for(int i=0;i<n;i++){
        cin>>num;
         max=Maximum(num,max);
         min=Minimum(num,min);
     }

    cout<<"The maximum number is "<<max<<endl;
    cout<<"The minimum number is " <<min<<endl;

   getch();
}
double Maximum(double num,double max){
      if(num>max){
        max=num;
        }
        return max;


}

double Minimum(double num,double min){
       if(num<min){
         min=num;
       }
       return min;

}