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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...