Breaking

Friday, 2 June 2017

Reverse Pattern Printing - Numbers

                     Reverse Pattern Printing - Numbers 

                        


Based on the input value of N, the program must print the pattern described below.

Input Format: 
First line will contain the value of N.

Output Format:
N lines will contain the number pattern as described below with each value separated by a single space.

Boundary Conditions:
1 <= N <= 50

Example Input/Output 1:
Input:
5

Output:
15 10 6 3 1
14  9 5 2
13 8 4
12 7
11

Example Input/Output 2:

Input:
3
Output: 
6 3 1
5 2
4              

Code:

#include <iostream>
using namespace std;
int main() 
{
int i,j,n,x,no,tot;
cin>>n;
tot=n;
        x=(n*(n+1))/2;  // To calculate maximum total element in Floyd triangle
for(i=n;i>0;i--)
   {   no=x;
       for(j=0;j<i;j++)
           {   
               cout<<no<<" ";
               no-=tot;
               tot--;
           }
           cout<<"\n";
           x--;
           tot=n;
   }
return 0;

}



1 comment:

  1. I am definitely enjoying your website. You definitely have some great insight and great stories.
    book printing

    ReplyDelete

Like