+ 1
Can someone teach me on the project about ticket office
How to get smallest age??
6 Antworten
0
This is how you get the smallest age in an array
int temp=ages[0];
for(int i=0;i<5;i++)
{
if(temp>ages[i])
temp=ages[i];
}
0
Explain to me your loop please
0
I cannot understand the if statement
0
But its working
0
First you need a variable (like temp in the example) that starts from the beginning of the array in order to compare all the values in the array inside a loop, then you create a "for" loop that has i as counter and repeats itself as the length of the array, then you define your if statement inside the loop with the condition that if temp(first value of the array) is bigger than the current number in the array change temp's value to the smaller number, this process is repeated until your loop is finished and temp gets smaller as it can and when your loop is finished it reaches the end of your array and the smallest number of all is found which is temp.
0
Thanks for the explaination