Pages

Monday, March 31, 2025

Palindromic Numbers problem in C++ but unique (MyLearnings!!)

 #include <iostream>

using namespace std;

/*
MyLearnings:-
1. I lacked visualization for spacing, and should've started from backward to forward which is correct way to do this code
*/
int main() {
    int n = 5;

    // outer loop
    for(int i = 1; i <= n; i++){
        // inner loop

        for(int space = 1; space <= n-i; space++){
            cout << " ";
        }
        // nums backward
        for(int j = i; j >= 1; j--){
            cout << j;
        }
        // nums forward
        for(int j = 2; j <= i; j++){
            cout << j;
        }
        cout << endl;
    }




    return 0;

}

OUTPUT-
1 212 32123 4321234 543212345

No comments:

Post a Comment

Stack using Linked List – Partial (University Exam Topic)

 #include <iostream> using namespace std; struct Node {     int data;     Node* next; }; class Stack {     Node* top; public:     Stac...