Pages

Wednesday, March 26, 2025

code to print N to 1 , MyMistakes! - important for review

 

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 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

Encode and Decode Strings - NeetCode.IO Solution by me + gemini pro 3.0 explained

  class Solution {         // encode: List of Strings -> String     public String encode ( List < String > strs) {         Stri...