AMCAT Pattern Programs for Recognition

AMCAT Pattern Programs, AMCAT Coding Pattern Questions, AMCAT Pattern Questions, AMCAT Pattern Recognition Programs and Questions with Solutions PDF, 1 3*2 4*5*6 Pattern in Java, Print Pattern(for n=4) 1 3*2 4*5*6 10*9*8*7 in Java, C, C++ etc. Solution are provided here with good time complexity Print pattern(for n=4) 1 3*2 4*5*6 10*9*8*7 in java

AMCAT Pattern based Questions

Go to Our AMCAT Programming Dashboard

Ques. Print the following Pattern and get the OutPut?

Input : n = 4
Output :
1
3*2
4*5*6
10*9*8*7

N=5
Output
1
3*2
4*5*6
10*9*8*7
11*12*13*14*15

Print Pattern(for n=4) 1 3*2 4*5*6 10*9*8*7 in Java, C, C++ etc

Program in C for AMCAT Pattern

#include
int main()
{
int i,j,n,count=0,k=0;
printf(“Enter N”);
scanf(“%d”,&n);
for(i=1;i<=n;i++)

count=k;
for(j=1;j<=i;j++)

if(i%2==0)
{
printf(“%d”,count+i);
count=count-1;
if(j!=i)printf(“*”);
k++;
}
else
{
count=count+1;
printf(“%d”,count);
if(j!=i)printf(“*”);
k++;
}
}
printf(“\n”);
}
return 0;
}

Program in Java for AMCAT Pattern

import java.io.*; 
import java.net.*; 
public class Selenium_Projext { 
public static void main(String[] args){ 

PrintPat(9); 
}

public static void PrintPat(int a)
{ int last=0;
for(int i=1;i<=a;i++)
{ last=last+i;
int l=i;

for(int j=last;l>0;l–)
{

System.out.print(j–);
if(l>1)
System.out.print(“*”);

}

System.out.println();
}
}}

In C++

// C++ implementation to print the following
// pyramid pattern
#include <bits/stdc++.h>
using namespace std;

// function to print the following pyramid pattern
void printPattern(int n)
{
int j, k = 0;

// loop to decide the row number
for (int i=1; i<=n; i++)
{
// if row number is odd
if (i%2 != 0)
{
// print numbers with the ‘*’ sign in
// increasing order
for (j=k+1; j<k+i; j++)
cout << j << “*”;
cout << j++ << endl;

// update value of ‘k’
k = j;
}

// if row number is even
else
{
// update value of ‘k’
k = k+i-1;

// print numbers with the ‘*’ in
// decreasing order
for (j=k; j>k-i+1; j–)
cout << j << “*”;
cout << j << endl;
}
}
}

// Driver program to test above
int main()
{
int n = 5;
printPattern(n);
return 0;
}

Time Complexity: O((n * (n + 1)) / 2)

Summary
Review Date
Reviewed Item
Pattern Questions
Author Rating
51star1star1star1star1star