Wipro NLTH Pattern Making Question: 2 (Trapezium)

Trapezium Pattern in C, Java

Here you will learn how to print the Trapezium Pattern in C language and Trapezium Pattern program in Java, Trapezium Pattern print in C++ – 

 

Ques. To print the trapezium pattern?

Please also post your code in the comments in different languages or same languages with short or better time complexity code.

If N = 4
1*2*3*4*17*18*19*20

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

 

#include<stdio.h>
int main ()
{
int n = 5, num = 1, i = 1, space = 0, k = 1, number = n;

for (i = 0; i < n; i++)
{
for (int j = 1; j <= space; j++)
{
printf (" ");
}
for (int m = 1; m < 2 * n - space; m++)
{
if (m % 2 == 0)
printf ("%s", "*");
else
printf ("%d", num++);
}

printf ("%s", "*");
for (int l = 1; l < 2 * n - space; l++)
{
if (l % 2 == 0)
printf ("%s", "*");
else
{
printf ("%d", k + number * number);
k++;
}
}
number--;
space = space + 2;
printf ("\n");
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
int main ()
{
int n = 5, num = 1, i = 1, space = 0, k = 1, number = n;
for (i = 0; i < n; i++)
{
for (int j = 1; j <= space; j++)
{
cout << " ";
}
for (int m = 1; m < 2 * n - space; m++)
{
if (m % 2 == 0)
cout << "*";
else
cout << num++;
}
cout << "*";

for (int l = 1; l < 2 * n - space; l++)
{
if (l % 2 == 0)
cout << "*";
else
{
cout << k + number * number;
k++;
}
}
number--;
space = space + 2;
cout << endl;
}
return 0;
}
class Main
{
public static void main (String[]args)
{
int count1 = 0, count2 = 0;
int N = 2;
for (int i = N; i >= 1; i--)
{
for (int j = N; j > i; j--)
System.out.print (" ");

for (int k = 1; k <= i; k++)
System.out.print (++count1 + "*");

for (int l = 1; l <= i; l++)
{
System.out.print (++count2 + i * i);
if (l != i)
System.out.print ("*");
}
System.out.println ();
}
}
}

NOTE:- Please do comment the code in other languages 🙂

Disclaimer-: The questions provided on this page are only model practice questions there is no surety that these questions have been previously asked in any company placement papers, these questions here only have the sole purpose to make you practice coding questions

2 comments on “Wipro NLTH Pattern Making Question: 2 (Trapezium)”


  • Gaurav

    # include
    # include

    void main()
    {
    int n,i,j,k,temp,count1,count2,count3=-1,temp2;
    printf(“Enter number n “);
    scanf (“%d”,&n);
    count1=1;
    count2=n*(n+1);
    temp=2*n;
    temp2=count2;
    for(i=1;i<=n;i++)
    {
    for(j=2;j<=i;j++)
    {
    printf(" ");
    }
    for(k=1;k<=temp;k++)
    {
    if(k<=temp/2)
    {
    printf("%d*",count1);
    count1++;
    count3++;
    if (k== temp/2) count2=count2-count3;
    }
    else
    {
    if(k==temp)
    {
    printf("%d",count2);

    }
    else
    {
    printf("%d*",count2);

    }
    temp2–;
    count2++;
    }
    }
    temp=temp-2;
    count3=-1;
    count2=temp2;
    printf("\n");
    }
    getch();
    }


  • akshay achz

    n=int(input())
    rval=1
    m=n
    k=1
    for i in range(n):
    lval=m*m+k
    for j in range(i*2):
    print(“-“,end=””)
    for j in range((n-i)):
    print(str(rval)+”*”,end=””)
    rval=rval+1
    for j in range(n-i):
    if(j==(n-i-1)):
    print(str(lval),end=””)
    else:
    print(str(lval)+”*”,end=””)
    lval=lval+1
    m=m-1
    k=k+(n-i)
    print()