How many ways can we use to find largest number in c++? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How many ways can we use to find largest number in c++?

The one way is if statement ,if else, nested if,....what else?

16th Nov 2020, 4:10 PM
Anas kayani
Anas kayani - avatar
6 Answers
+ 2
Anas kayani that's ok, let me explain with examples. 1) one way is to perform the comparison whenever you inputting the integers and keep track of largest number entered till now. Here is one exmple using it 👇 https://code.sololearn.com/chc7KBgOb7YZ/?ref=app 2) other way is to sort the array in increasing order and display the last element. Here is one exmple using it 👇 https://code.sololearn.com/cU3Z4i4SiFlm/?ref=app There are many other ways of doing it also, but these are the most common one.
16th Nov 2020, 4:53 PM
Arsenic
Arsenic - avatar
+ 1
I cannot understand
16th Nov 2020, 4:41 PM
Anas kayani
Anas kayani - avatar
+ 1
I think there's infinirely many different ways. Here's one, but i think there are even crazier ones https://code.sololearn.com/cP1LtPA7WdBz/?ref=app
16th Nov 2020, 7:47 PM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
0
They have done using for loop
16th Nov 2020, 4:21 PM
Anas kayani
Anas kayani - avatar
0
Maximum ways to find largest of numbers ?
16th Nov 2020, 4:23 PM
Anas kayani
Anas kayani - avatar
0
Only 2 ways 1) independent comparison { will take liner time O(n) } 2) sorting { time complexity will depend on sorting algorithm used }
16th Nov 2020, 4:40 PM
Arsenic
Arsenic - avatar