Inverted Trapezium Pattern

 Coding Problem Keys 

 Inverted Trapezium Pattern 

 Problem Statement 

The program must accept an integer N as the input. The program must print the desired pattern as shown in the Example Input/Output sections.

 Input Format 

The first line contains the value of N.

 Output Format 

The first N lines contain the desired pattern as shown in the Example Input/Output sections.

 Boundary Condition(s) 

1 <= N <= 100

 Example Input/Output 1 

 Input 

4

 Output 

- - - 10 11
- - 8 9 12 13
- 5 6 7 14 15 16
1 2 3 4 17 18 19 20

 Example Input/Output 2 

 Input 

5

 Output 

- - - - 15 16
- - - 13 14 17 18
- - 10 11 12 19 20 21
- 6 7 8 9 22 23 24 25
1 2 3 4 5 26 27 28 29 30

 Max Execution Time Limit: 5000 millisecs 

 Solution 

 Programming Language: C Language 

#include <stdio.h>
void print(int n){
    while(n-->0)printf("- ");
}
int main(){
    int n;
    scanf("%d",&n);
    int var= (n*(n+1))/2;
    int p1=var,p2=var+1;
    for(int i=1;i<=n;i++){
        print(n-i);
        for(int j=1;j<=i;j++){
            printf("%d ",p1+j-1);
        }
        p1=p1-(i+1);
        for(int j=1;j<=i;j++){
            printf("%d ",p2++);
        }
        printf("\n");
    }
}

// Published By PKJCODERS

 Programming Language: Python 3 Language 

n=int(input())
l=[];c=1
for i in range(n,0,-1):
    temp=[j for j in range(c,c+i)]
    l.append(temp)
    c+=i
l=l[::-1]
for i in range(1,n+1):
    temp=['-' for j in range(n-i)]
    temp+=l[i-1]
    temp+=[j for j in range(c,c+i)]
    print(*temp)
    c+=i

# Published By PKJCODERS

 (Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.) 

Comments

Popular Posts

Nielsen

Mango Distribution

Prime or Not - CTS Pattern

Consonants Count in Sliding Window

HCLTech

Split String & Sort

Pattern Printing Middle Letter - Odd Length String