- 1

How to find largest number in array

Array c++

4th Jul 2021, 11:21 AM
ANIL JOSHI
ANIL JOSHI - avatar
11 odpowiedzi
+ 1
#include <iostream> using namespace std; int main() { int ages[3]; for (int i = 0; i < 3; ++i) { cin >> ages[i]; } //your code goes here int min=ages[0]; for(int i=0;i<3;i++){ if(ages[i]<min){ min=ages[i]; } } cout<<min; return 0; }
4th Jul 2021, 1:45 PM
ANIL JOSHI
ANIL JOSHI - avatar
+ 2
Create a variable max and set a default value as 0 , go though each element and check if that elements is greater than max then set the value of max to that elements! This is a hint, try it! :D
4th Jul 2021, 11:24 AM
Abhiyantā
Abhiyantā - avatar
+ 1
ANIL JOSHI You have to compare 1st value with next value to get min value so you have to use loop. int min = ages[0]; for (int i = 1; i < 5; i++) { if (ages[i] < min) { min = ages[i]; } }
4th Jul 2021, 12:44 PM
A͢J
A͢J - avatar
+ 1
Ok I got it this is right code
4th Jul 2021, 1:45 PM
ANIL JOSHI
ANIL JOSHI - avatar
0
Write code
4th Jul 2021, 11:26 AM
ANIL JOSHI
ANIL JOSHI - avatar
0
Problem in this code to find min no in array
4th Jul 2021, 11:37 AM
ANIL JOSHI
ANIL JOSHI - avatar
4th Jul 2021, 6:33 PM
Rahul Kumar Mandal
Rahul Kumar Mandal - avatar
- 1
#include <iostream> using namespace std; int main() { int i,ages[i]; for (int i = 0; i < 5; ++i) { cin >> ages[i]; } //your code goes here int min=ages[0]; if(ages[i]<min) { min=ages[i]; }
4th Jul 2021, 11:36 AM
ANIL JOSHI
ANIL JOSHI - avatar
- 1
Code
4th Jul 2021, 1:09 PM
SHAKIR AHMAD
SHAKIR AHMAD - avatar