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
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;
}
1*2*3*4*17*18*19*20
5*6*7*14*15*16
8*9*12*13
10*11
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;
}
This Blog is Hard work !
Can you give me a treat 😌
0 Comments