int i, min = 0;
for (i = 0; i < 10; i++)
{
cin >> number;
if (i == 0) // Condition A
min = number;
else if (min > number) // Condition B
min = number;
}
cout << min;
Hello, the above source code is the code that can find the smallest number among the numbers received as input. Why is if(i==0)
a conditional statement for finding the smallest number? Isn't i==0
the first number you entered? I'm a beginner in coding, so I don't understand well. Please explain.
It is a code that compares min and input values while going around the repetition door to store the smallest number in min.
What value does the min need to have for comparison?
So, at the beginning of a repeating sentence, the input value is substituted into min without comparing it (if(i==0) min=number;), and then compared to min from the repetition, and stored in min if the input value is less than min.
Eventually, the smallest value of the number entered is stored. Even if the iteration is one time, the smallest value will be stored by the substitution.
1235 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
856 Uncaught (inpromise) Error on Electron: An object could not be cloned
771 GDB gets version error when attempting to debug with the Presense SDK (IDE)
776 M2 Mac fails to install rbenv install 3.1.3 due to errors
© 2025 OneMinuteCode. All rights reserved.