MyLearnings:
The expression i >= 1 is a condition that checks whether the variable i is greater than or equal to 1. Here's what it means in simple terms:
- If i is 1 or any number larger than 1 (like 2, 3, 10, etc.), the condition i >= 1 is true.
- If i is less than 1 (like 0, -1, -5, etc.), the condition i >= 1 is false.
#include <iostream>using namespace std;
// print from n to 1int main(){ int n;
cout << "enter a num: "; cin >> n;
for(int i = n; i >= 1; i--){ cout << i << " "; }
return 0;
}
#include <iostream>
using namespace std;
// print from n to 1
int main(){
int n;
cout << "enter a num: ";
cin >> n;
for(int i = n; i >= 1; i--){
cout << i << " ";
}
return 0;
}
No comments:
Post a Comment