YouTip LogoYouTip

Cpp Examples Largest Number Among Three

# C++ Example - Find the Largest Number Among Three [![Image 3: C++ Examples](#) C++ Examples](#) We input three numbers through the screen and find the largest number. ## Example - Using if #includeusing namespace std; int main(){float n1, n2, n3; cout<>n1>>n2>>n3; if(n1>= n2&&n1>= n3){cout<<"Largest number is: "<= n1&&n2>= n3){cout<<"Largest number is: "<= n1&&n3>= n2){cout<<"Largest number is: "<<n3; }return 0; } The output of the above program is: Enter three numbers: 2.38.3-4.2Largest number is: 8.3 ## Example - Using if...else #includeusing namespace std; int main(){float n1, n2, n3; cout<>n1>>n2>>n3; if((n1>= n2)&&(n1>= n3))cout<<"Largest number is: "<= n1)&&(n2>= n3))cout<<"Largest number is: "<<n2; else cout<<"Largest number is: "<<n3; return 0; } The output of the above program is: Enter three numbers, separated by spaces: 2.38.3-4.2Largest number is: 8.3 ## Example - Using Nested if...else #includeusing namespace std; int main(){float n1, n2, n3; cout<>n1>>n2>>n3; if(n1>= n2){if(n1>= n3)cout<<"Largest number is: "<<n1; else cout<<"Largest number is: "<= n3)cout<<"Largest number is: "<<n2; else cout<<"Largest number is: "<<n3; }return 0
← Server TimeJsref Return β†’