I am really new in coding and I just want to know why I don't need brackets after my second for loop and after my if statement like my 1st example. Second example made more sense to me but was just wondering.
int num[10], min;
for (int i = 0; i < 10; i++) {
cout << "enter 10 numbers" << endl;
cin >> num[i];
}
min = num[0];
for (int i = 0; i < 10; i++)
if (num[i] < min)
min = num[i];
cout << "The smallest number is : " << min;
system("pause");
return 0;
int num[10], min;
for (int i = 0; i < 10; i++) {
cout << "enter 10 numbers" << endl;
cin >> num[i];
}
min = num[0];
for (int i = 0; i < 10; i++) {
if (num[i] < min) {
min = num[i];
}
}
cout << "The smallest number is : " << min;
system("pause");
return 0;
Aucun commentaire:
Enregistrer un commentaire