Programs for printing Pyramid patterns – TechWorld4U09
Programs for printing Pyramid patterns in C
#include <stdio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
Output
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Programs for printing Pyramid patterns in Java
import java.io.*;
// Java code to demonstrate star patterns
public class GeeksForGeeks
{
// Function to demonstrate printing pattern
public static void printStars(int n)
{
int i, j;
// outer loop to handle number of rows
// n in this case
for(i=0; i<n; i++)
{
// inner loop to handle number of columns
// values changing acc. to outer loop
for(j=0; j<=i; j++)
{
// printing stars
System.out.print("* ");
}
// ending line after each row
System.out.println();
}
}
// Driver Function
public static void main(String args[])
{
int n = 5;
printStars(n);
}
}
Output
*
* *
* * *
* * * *
* * * * *
Program for printing Pyramid patterns in Python
def pypart(n):
# outer loop to handle number of rows
# n in this case
for i in range(0, n):
# inner loop to handle number of columns
# values changing acc. to outer loop
for j in range(0, i+1):
# printing stars
print("* ",end="")
# ending line after each row
print("\r")
# Driver Code
n = 5
pypart(n)
TCS Syllabus 2022 PDF Download | TCS Exam Pattern TCS Syllabus 2022 & Test Pattern PDF Download for Freshers: Freshers who are looking forward to cracking the TCS Selection Process 2022, can prepare well with the Read more…
How To Enable Super Thanks Option on YouTube Video | Enable thanks option in YouTube channel Your QueriesSuper ThanksSuper Thanks YoutubeSuper Thanks kya hota haiHow to enable super thanksSuper Thanks kya haiWhat is the super Read more…
TCS NQT Coding Question 2022 Problem Statement – An automobile company manufactures both a two wheeler (TW) and a four wheeler (FW). A company manager wants to make the production of both types of vehicle according Read more…
0 Comments