Usb 20
Usb 20
Examples :
Input : 5
Output:
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
void pattern(int n)
{
int i, j;
// Driver Code
int main()
{
pattern(7);
return 0;
}
// This code is contributed by bunnyra
Output
* * * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
Examples :
Input : 5
Output:
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
void pattern(int n)
{
int i, j;
Output
* *
* * * *
* * * * * *
* * * * * * * *
* * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * *
* * * * * * * *
* * * * * *
* * * *
* *
Examples:
Output:
\*******/
*\*****/*
**\***/**
***\*/***
****/****
***/*\***
**/***\**
*/*****\*
/*******\
Output :
\******/
*\****/*
**\**/**
***\/***
***/\***
**/**\**
*/****\*
/******\
C++ Python3
void pattern(int n)
{
// for traversing of rows
for (int i = 1; i <= n; i++) {
// for traversing of columns
for (int j = 1; j <= n; j++) {
// conditions for left-dia
// right-diagonal
if (i == j || i + j == (n
if (i + j == (n + 1))
cout << "/";
}
else {
cout << "\\";
}
}
else
cout << "*";
}
cout << endl;
}
}
// Driver Code
int main()
{
pattern(9);
return 0;
}
// This code is contributed by Nitin K
Output
\*******/
*\*****/*
**\***/**
***\*/***
****/****
***/*\***
**/***\**
*/*****\*
/*******\
Examples :
Input : 8
Output :
7 6 5 4 3 2 1 0
6 5 4 3 2 1 0
5 4 3 2 1 0
4 3 2 1 0
3 2 1 0
2 1 0
1 0
C++
void pattern(int n)
{
// for traversing of rows
for (int i = 1; i <= n; i++) {
int k = n - i;
// for traversing of columns
for (int j = 1; j <= n; j++) {
if (j <= (n + 1) - i) {
cout << k << " ";
k--;
}
else {
cout << " ";
}
}
cout << endl;
}
}
// Driver Code
int main()
{
pattern(8);
return 0;
}
// This code is contributed by Nitin K
Output
7 6 5 4 3 2 1 0
6 5 4 3 2 1 0
5 4 3 2 1 0
4 3 2 1 0
3 2 1 0
2 1 0
1 0
Examples:
Input: 7
Output:
8 2
14 9 3
19 15 10 4
23 20 16 11 5
26 24 21 17 12 6
28 27 25 22 18 13 7
C++
void pattern(int n)
{
int p, k = 1;
// for traversing of rows
for (int i = 1; i <= n; i++) {
p = k;
// for traversing of columns
for (int j = 1; j <= i; j++) {
cout << p << " ";
p = p - (n - i + j);
}
cout << endl;
k = k + 1 + (n - i);
}
}
// Driver Code
int main()
{
pattern(7);
return 0;
}
// This code is contributed by Nitin K
Output
8 2
14 9 3
19 15 10 4
23 20 16 11 5
26 24 21 17 12 6
28 27 25 22 18 13 7
pattern-printing
Recommended Articles
1. Programs to print Triangle and Diamond
patterns using recursion
2. Programs for printing pyramid patterns in
Python
3. Programs for printing pyramid patterns in Java
4. PHP programs for printing pyramid patterns
5. Programs for printing pyramid patterns using
recursion
6. Programs for printing pyramid patterns in C++
7. Program to print interesting pattern
8. Program to print solid and hollow square
patterns
9. Program to print solid and hollow rhombus
patterns
10. Program to print hollow rectangle or square
star patterns
11. Program to print right and left arrow patterns
12. Print di"erent star patterns in SQL
13. Program to print diagonal star patterns
14. Print Patterns in PL/SQL
15. Recursive program to print triangular
patterns
16. C Program to Print Floyd's Triangle Pyramid
Patterns
17. C/C++ Ternary Operator - Some Interesting
Observations
18. Interesting facts about switch statement in C
19. Interesting Facts about Macros and
Preprocessors in C
20. Some Interesting facts about default
arguments in C++
21. Interesting facts about strings in Python | Set
1
22. Interesting facts about strings in Python | Set
2 (Slicing)
23. C++ bitset interesting facts
24. Interesting Facts in C Programming
25. Interesting facts about data-types and
modifiers in C/C++
Company
About Us
Careers
In Media
Contact Us
Privacy Policy
Copyright Policy
Advertise with us
Learn
DSA
Algorithms
Data Structures
SDE Cheat Sheet
Machine Learning
CS Subjects
Video Tutorials
Courses
NEWS
Top News
Technology
Work & Career
Business
Finance
Lifestyle
Knowledge
Languages
Python
Java
CPP
Golang
C#
SQL
Kotlin
Web Development
Web Tutorials