Computer Science, asked by sdhyan865, 23 hours ago

write a c++ progrem to find largest ,second largest, and smallest number using switch statement​

Answers

Answered by sohail020803
1

Answer:

here is ur answer bro

Explanation:

#include <iostream>

using namespace std;

int main()

{

cout << "\n\nWelcome to Studytonight :-)\n\n\n";

cout << " ===== Program to find the Largest and the Smallest number among 3 numbers ===== \n\n";

//variable declaration

int n1, n2, n3, smallest, largest;

//taking input from the command line (user) all at once

cout << " Enter the three numbers : \n\n\n";

cin >> n1 >> n2 >> n3;

//assign initial value for comparison (as the undefined variables store a random value)

smallest = n1;

largest = n2;

//logic to find the Smallest and the Largest number - Remember, each variable stores only the latest value inserted into it.

if (n2 < smallest)

{

smallest = n2;

}

if (n3 < smallest)

{

smallest = n3;

}

if (n3 > largest)

{

largest = n3;

}

if (n2 > largest)

{

largest = n2;

}

cout << "\n\n The Smallest number among ( " << n1 << ", " << n2 << ", " << n3 << " ) is : " << smallest;

cout << "\n\n The Largest number among ( " << n1 << ", " << n2 << ", " << n3 << " ) is : " << largest;

cout << "\n\n\n";

return 0;

}

Similar questions