Print the Trapezium Pattern | AMCAT Automata Question - Pattern 3

Ques. Print the Trapezium Pattern

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


Trapezium Problem-SimpleWay2Code



C Program  Solution:

#include <stdio.h>
int main(void) {

    int num = 4; 
    int space; 
    int i, j, lterm, rterm; 

    // The terms on the LHS of the pattern  

    lterm = 1;  

    // The terms on the RHS of the pattern 

    rterm = num * num + 1; 

    for (i = num; i > 0; i--) { 


        // To print number of spaces  

        for(space = num;space > i;space--) 
            printf(" "); 

          for(j = 1; j <= i; j++) { 

            printf("%d",lterm); 

            printf("*"); 

            lterm++; 

        } 

        for (j = 1; j <= i; j++) { 

            printf("%d",rterm); 

            if (j < i) 

                printf("*"); 

            rterm++; 

        } 

// To get the next term on RHS of the Pattern  

        rterm = rterm - (i - 1) * 2 - 1; 

        printf("\n"); 

    } 
    return 0;
}







Trapezium - SimpleWay2Code


Check Out More Questions from AMCAT Automata Test : Click here

This Blog is Hard work !

Can you give me a treat 😌

Post a Comment

0 Comments