dimanche 11 décembre 2022

Comparison of three number

i am comparing 3 number and the output must show which one is largest and which one is smallest but the thing is what if there are unlimited number I will have to write a lot of ifs and else, so for that purpose can you pls convert this into for loop for me.


int main()
{
    float number1;
    float number2;
    float number3;
    cout << "Please enter Number 01:";
    cin >> number1;
    cout << "Please enter Number 02:";
    cin >> number2;
    cout << "Please enter Number 03:";
    cin >> number3;
    if (number1 > number2 && number1 > number3) {
        cout <<”Number 01 is maximum…”<< endl;
    }
    else if (number2 > number1 && number2 > number3) {
        cout << "Number 02 is maximum…" << endl;
    }
    else if (number3 > number1 && number3 > number2) {
        cout << "Number 03 is maximum…" << endl;
    }
    Else
    {
        Cout <<”Invalid entry from maximum”<< endl;
    }
    If(number1 < number2 && number1 < number3)
    {
        Cout <<”Number 01 is minimum..”<< endl;
    }
    else if (number2 < number1 && number2 < number3)
    {
        cout << "Number 02 is minimum…" << endl;
    }
    else if (number3 < number1 && number3 < number2)
    {
        cout << "Number 03 is minimum…" << endl;
    }
    Else
    {
        Cout<<”invalid entry for minimum”<<endl;
    }
    Return 0;

Aucun commentaire:

Enregistrer un commentaire