Pattern 1
1 1 1 2 1 2 3 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5
Code for pattern 1
Java
C++
Python
Java
import java.util.*;
public class Main {
public static void main(String[] args) {
int i, j, number, n = 6;
for (i = 1; i < n; i++) {
number = 1;
if (i % 2 == 1) {
for (j = 1; j <= i; j++) {
System.out.print(j + " ");
number++;
}
System.out.println();
}
for (j = 1; j <= i; j++) {
System.out.print(j + " ");
number++;
}
System.out.println();
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
int i;
int j;
int number;
int n = 6;
for (i = 1; i < n; i++)
{
number = 1;
if (i % 2 == 1)
{
for (j = 1; j <= i; j++)
{
std::cout << std::to_string(j) + " ";
number++;
}
std::cout << std::endl;
}
for (j = 1; j <= i; j++)
{
std::cout << std::to_string(j) + " ";
number++;
}
std::cout << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
i = 0
j = 0
number = 0
n = 6
i = 1
while (i < n) :
number = 1
if (i % 2 == 1) :
j = 1
while (j <= i) :
print(str(j) + " ", end ="")
number += 1
j += 1
print()
j = 1
while (j <= i) :
print(str(j) + " ", end ="")
number += 1
j += 1
print()
i += 1
if __name__=="__main__":
Main.main([])
Pattern 2
1 2 3 4 5 1 2 3 4 5 1 2 3 4 1 2 3 1 2 3 1 2 1 1
Code for pattern 2
Java
C++
Python
Java
import java.util.*;
public class Main {
public static void main(String[] args) {
int i, j, number, n = 6;
for (i = 5; i >= 1; i--) {
number = 1;
if (i % 2 == 1) {
for (j = 1; j <= i; j++) {
System.out.print(j + " ");
number++;
}
System.out.println();
}
for (j = 1; j <= i; j++) {
System.out.print(j + " ");
number++;
}
System.out.println();
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
int i;
int j;
int number;
int n = 6;
for (i = 5; i >= 1; i--)
{
number = 1;
if (i % 2 == 1)
{
for (j = 1; j <= i; j++)
{
std::cout << std::to_string(j) + " ";
number++;
}
std::cout << std::endl;
}
for (j = 1; j <= i; j++)
{
std::cout << std::to_string(j) + " ";
number++;
}
std::cout << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
i = 0
j = 0
number = 0
n = 6
i = 5
while (i >= 1) :
number = 1
if (i % 2 == 1) :
j = 1
while (j <= i) :
print(str(j) + " ", end ="")
number += 1
j += 1
print()
j = 1
while (j <= i) :
print(str(j) + " ", end ="")
number += 1
j += 1
print()
i -= 1
if __name__=="__main__":
Main.main([])
Pattern 3
0 10 010 1010 01010
Code for pattern 3
Java
C++
Python
Java
import java.util.*;
public class Main {
public static void main(String[] args) {
for (int i = 0; i <= 5; i++) {
for (int j = 0; j <= 5; j++) {
if(j-i<0){
if((j+i)%2==0) {
System.out.print("1");
} else {
System.out.print("0");
}
}
else
System.out.print(" ");
}
System.out.println();
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
for (int i = 0; i <= 5; i++)
{
for (int j = 0; j <= 5; j++)
{
if (j - i < 0)
{
if ((j + i) % 2 == 0)
{
std::cout << "1";
}
else
{
std::cout << "0";
}
}
else
{
std::cout << " ";
}
}
std::cout << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
i = 0
while (i <= 5) :
j = 0
while (j <= 5) :
if (j - i < 0) :
if ((j + i) % 2 == 0) :
print("1", end ="")
else :
print("0", end ="")
else :
print(" ", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
Main.main([])
Pattern 4
5 4 3 2 1 5 4 3 2 5 4 3 5 4 5
Code for pattern 4
Java
C++
Python
Java
import java.util.*;
public class Main {
public static void main(String[] args) {
for (int i = 1; i <=5; i++) {
{
for (int j = 5; j >=i; j--) {
System.out.print(j + " ");
}
System.out.println();
}
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 5; j >= i; j--)
{
std::cout << std::to_string(j) + " ";
}
std::cout << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
i = 1
while (i <= 5) :
j = 5
while (j >= i) :
print(str(j) + " ", end ="")
j -= 1
print()
i += 1
if __name__=="__main__":
Main.main([])
Pattern 5
1 1 0 1 2 3 1 0 1 0 1 2 3 4 5
Code for pattern 5
Java
C++
Python
Java
public class Main {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
{
for (int j = 1; j <= i; j++) {
if (i % 2 == 1) {
System.out.print(j + " ");
} else {
if (j % 2 == 1) {
System.out.print("1" + " ");
} else {
System.out.print("0" + " ");
}
}
}
System.out.println();
}
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
if (i % 2 == 1)
{
std::cout << std::to_string(j) + " ";
}
else
{
if (j % 2 == 1)
{
std::cout << "1 ";
}
else
{
std::cout << "0 ";
}
}
}
std::cout << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
i = 1
while (i <= 5) :
j = 1
while (j <= i) :
if (i % 2 == 1) :
print(str(j) + " ", end ="")
else :
if (j % 2 == 1) :
print("1 ", end ="")
else :
print("0 ", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
Main.main([])
Pattern 6
10 9 9 8 8 8 7 7 7 7 6 6 6 6 6
Code for pattern 6
Java
C++
Python
Java
public class Main {
public static void main(String[] args) {
int num=10;
for(int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
System.out.print(num+" ");
}
System.out.println();
num--;
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
int num = 10;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= i; j++)
{
std::cout << std::to_string(num) + " ";
}
std::cout << std::endl;
num--;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
num = 10
i = 1
while (i <= 5) :
j = 1
while (j <= i) :
print(str(num) + " ", end ="")
j += 1
print()
num -= 1
i += 1
if __name__=="__main__":
Main.main([])
Pattern 7
O P P Q Q Q R R R R S S S S S
Code for pattern 7
Java
C++
Python
Java
public class Main {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
String s = "O";
if (i > 1) {
s = String.valueOf((char)('P' + i - 2));
for (int j = 1; j < i; j++) {
s += s.charAt(0);
}
}
System.out.println(s);
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
for (int i = 1; i <= 5; i++)
{
std::string s = "O";
if (i > 1)
{
s = to_string((char)('P' + i - 2));
for (int j = 1; j < i; j++)
{
s += s[0];
}
}
std::cout << s << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
i = 1
while (i <= 5) :
s = "O"
if (i > 1) :
s = "".join(chr((ord('P') + i - 2)))
j = 1
while (j < i) :
s += s[0]
j += 1
print(s)
i += 1
if __name__=="__main__":
Main.main([])
Pattern 8
1# 2# 3# 4# 5# 6# 7# 8# 9# 10#
Code for pattern 8
Java
C++
Python
Java
import java.util.*;
public class Main {
public static void main(String[] args) {
int count =1;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 54; j++) {
if(j-i<=0 )
System.out.print(count++ +"# ");//
else
System.out.print("");
}
System.out.println();
}
}
}
C++
// Include header file
#include
#include
#include
class Main
{
public:
static void main(std::vector &args)
{
int count = 1;
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 54; j++)
{
if (j - i <= 0)
{
std::cout << std::to_string(count++) + "# ";
}
else
{
std::cout << "";
}
}
std::cout << std::endl;
}
}
};
int main(int argc, char **argv){
std::vector parameter(argv + 1, argv + argc);
Main::main(parameter);
return 0;
};
Python
class Main :
@staticmethod
def main( args) :
count = 1
i = 0
while (i < 4) :
j = 0
while (j < 54) :
if (j - i <= 0) :
print(str(count += 1) + "# ", end ="")
else :
print("", end ="")
j += 1
print()
i += 1
if __name__=="__main__":
Main.main([])