Header Ads Widget

Pyramid Number Pattern | coding ninjas solution

Pyramid Number Pattern
Pattern for N = 4
   1
  212
 32123
4321234

Input format : N (Total no. of rows)

Output format : Pattern in N lines

Sample Input :
5
Sample Output :
        1
      212
    32123
  4321234
543212345

 

Code(c++):-

#include<iostream>
using namespace std;

int main(){
  
     int row;
    cin>>row;
    for(int i=1;i<=row;i++)
    {
        for(int j=1;j<=row-i;j++)
        {
            printf(" ");
        }
        for(int j=-i;j<=i;j++)
        {
            if(j==0||j==1)
            {
                continue;
            }
            printf("%d", abs(j));
        }
        printf("\n");
    }
    return 0;

}


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-