Print Pyramid Pattern in C and Java - Techie Delight PDF
Print Pyramid Pattern in C and Java - Techie Delight PDF
Techie Delight
Coding made easy
Pattern 1: Pyramid
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 1/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
#include <stdio.h>
int main(void)
{
// n is number of rows
int n = 5;
int i, j, k;
Java
This website uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
other conditions. Read our Privacy Policy
1 class Pattern
2 {
3 public static void main(Strin Close and accept
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 2/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
4 {
5 // n is number of rows
6 final int n = 5;
7
8 // Do for each row
9 for (int i = 1; i <= n; i
10 {
11 // Print space
12 for (int j = i; j < n
13 System.out.print(
14 }
15
16 // Print '*'
17 for (int k = 1; k < 2
18 System.out.print(
19 }
20
21 // Move to the next l
22 System.out.print(Syst
23 }
24 }
25 }
Download
Run Code
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 3/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
1 #include <stdio.h>
2
3 int main(void)
4 {
5 // n is number of rows
6 int n = 5;
7
8 int i, j, k;
9
10 // do for each row
11 for (i = n; i >= 1; i--)
12 {
13 // print space
14 for (j = n; j > i; j--)
15 printf(" ");
16
17 // print '*'
18 for (k = 1; k < 2*i; k++)
19 printf("*");
20
21 // move to the next line
22 printf("\n");
23 }
24
25 return 0;
26 }
Download
Run Code
Java
1 class Pattern
2 {
3 public static void main(Strin
4 {
5 // n is number of rows
6 final int n = 5;
7
8 // Do for each row
9 for (int i = n; i >= 1; i
10 {
11 // Print space
12 for (int j = n; j > i
This website
13 uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
System.out.print(
other conditions.
14 Read our Privacy
} Policy
15
16 // Print '*'
Close and accept
17 for (int k = 1; k < 2
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 4/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
18 System.out.print(
19 }
20
21 // Move to the next l
22 System.out.print(Syst
23 }
24 }
25 }
Download
Run Code
*
* *
* *
* *
* * * * * * * * *
1 #include <stdio.h>
2
3 int main(void)
4 {
5 // n is number of rows
6 int n = 5;
7
8 int i, j, k;
9
10 // do for each row
11 for (i = 1; i <= n; i++)
12 {
This website
13 uses cookies. By using
// print this site you agree to the use of cookies, our policies, copyright terms and
space
14 for (j = i; j < n; j++)
other conditions. Read our Privacy Policy
15 printf(" ");
16
17 // print '*' Close and accept
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 5/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
Download
Run Code
Java
1 class Pattern
2 {
3 public static void main(Strin
4 {
5 // n is number of rows
6 final int n = 5;
7
8 // Do for each row
9 for (int i = 1; i <= n; i
10 {
11 // Print space
12 for (int j = i; j < n
13 System.out.print(
14 }
15
16 // Print '*'
17 for (int k = 1; k < 2
18 {
19 // Print '*' for
20 if (i == n || (k
21 System.out.pr
22 }
23 else {
24 System.out.pr
25 }
26 }
27
28 // Move to the next l
This website uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
29 System.out.print(Syst
other conditions.
30 Read}our Privacy Policy
31 }
32 } Close and accept
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 6/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
Download
Run Code
* * * * * * * * *
* *
* *
* *
*
1 #include <stdio.h>
2
3 int main(void)
4 {
5 // n is number of rows
6 int n = 5;
7
8 int i, j, k;
9
10 // do for each row
11 for (i = n; i >= 1; i--)
12 {
13 // print space
14 for (j = n; j > i; j--)
15 printf(" ");
16
17 // print '*'
18 for (k = 1; k < 2*i; k++)
19 {
20 // print '*' for boun
21 if (i == n || (k == 1
22 printf("*");
This website uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
23 else
other conditions. Read our Privacy Policy
24 printf(" ");
25 }
26 Close and accept
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 7/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
Download
Run Code
Java
1 class Pattern
2 {
3 public static void main(Strin
4 {
5 // n is number of rows
6 final int n = 5;
7
8 // Do for each row
9 for (int i = n; i >= 1; i
10 {
11 // Print space
12 for (int j = n; j > i
13 System.out.print(
14 }
15
16 // Print '*'
17 for (int k = 1; k < 2
18 // Print '*' for
19 if (i == n || (k
20 System.out.pr
21 }
22 else {
23 System.out.pr
24 }
25 }
26
27 // Move to the next l
28 System.out.print(Syst
29 }
30 }
31 }
Download
Run Code
This website uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
other conditions. Read our Privacy Policy
(1 votes, average: 5.00 out of 5)
Close and accept
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 8/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
Sharing is caring:
C, Java, Misc
Leave a Reply
b i link b-quote u ul ol li
code spoiler
This website uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
Start the discussion (Set your
other conditions. Read our Privacy Policy
avatar at
https://gravatar.com/)
Close and accept
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 9/10
9/3/2019 Print pyramid pattern in C and Java - Techie Delight
Subscribe
This website uses cookies. By using this site you agree to the use of cookies, our policies, copyright terms and
other conditions. Read our Privacy Policy
https://www.techiedelight.com/c-program-print-pyramid-pattern/ 10/10