- 1
How to find largest number in array
Array c++
9 Antworten
+ 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;
}
+ 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
+ 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];
}
}
+ 1
Ok I got it this is right code
0
Write code
0
Problem in this code to find min no in array
- 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];
}
- 1
Code