Finding Maximum number of an array in a read file | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

Finding Maximum number of an array in a read file

Hi guys, I have a homework which needs the maximum number of a class and the information of the classes are in a file. First I wrote the function of reading the file. Second I should write the function of finding the max number... and after these i have to write the main function. But I have a problem with writing the function of finding the max number Can you please help me with that?

19th Jan 2018, 12:50 PM
Melika Baghooee
4 Antworten
+ 1
Can you share the code with your progress to the problem? That way, It will be easier to help.
19th Jan 2018, 1:28 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Yeah, But my entire code has 153 lines and it’s hard to explain the whole... But to make my problem more clear I would say: I need an algorithm that gives me the maximum number of n numbers from an array in a file...
19th Jan 2018, 1:36 PM
Melika Baghooee
+ 1
You may use a built-in function, max_element(), from <algorithm>. www.cplusplus.com/reference/algorithm/max_element Eg : int arr[6] = {1,2,48,2,1,22}; cout<<max_element(arr,arr+6); // Prints 2, the position of the max element.
19th Jan 2018, 1:38 PM
Kinshuk Vasisht
Kinshuk Vasisht - avatar
+ 1
Thanks, I’ll try it 😉
19th Jan 2018, 1:42 PM
Melika Baghooee