Reverse Pattern Printing - Numbers ID:2671


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

 

#include <stdio.h>

int main(int argc, char** argv)

{

int n;

scanf("%d",&n);

int first=(n*(n+1))/2;

for(int i=0;i<n;i++)

{

    int val=n;

    int temp=first;

   printf("%d ",temp);

    for(int j=0;j<n-i-1;j++)

    {

        printf("%d ",temp-val);

        temp=temp-val;

        val-=1;

    }

    first-=1;

   printf("\n");

}

}

Comments

Popular Posts