Q. Write a program to print full pyramid pattern using stars.
Full Pyramid Example:-
Full Pyramid Star Pattern * * * * * * * * * * * * * * * * * * * * * * * * *
Full Pyramid Program
#include<stdio.h> int main() { int i, j, rows,k=0; printf("Enter number of rows: "); scanf("%d", &rows); for (i=1; i<=rows; ++i,k=0) { for (j=1; j<=rows-i; ++j) { printf(" "); } while (k!=2*i-1) { printf("* "); ++k; } printf("\n"); } return 0; }
// C++ program to print full pyramid pattern using stars #include <iostream> using namespace std; int main() { int i, j, n, k = 0; cin >> n; for(i = 1; i <= n; ++i, k = 0) { for(j = 1; j <= n – i; ++j) { cout << " "; } while(k != 2 * i-1) { cout << "* "; ++k; } cout << endl; } return 0; }
public class LFC { public static void main(String[] args) //driver function { int rows=5, i, j, k = 0; for(i = 1; i <= rows; ++i, k = 0) { for(j = 1; j <= rows-i; ++j) { System.out.print(" "); } while(k != 2 * i-1) { System.out.print("* "); ++k; } System.out.print("\n"); } } }
def fullpy(n): for i in range(1, n+1): k=0 for j in range(1, n-i+1): print(" ", end = "") while(k != 2 * i-1): print("* ", end = "") k = k + 1 # ending line after each row print("\r") # Driver Code print("Enter number of rows: ") n = int(input()) fullpy(n)
#include<stdio.h> int main() { int i, j, rows,k=0; printf("Enter number of rows: "); scanf("%d", &rows); for (i=1; i<=rows; ++i,k=0) { for (j=1; j<=rows-i; ++j) { printf(" "); } while (k!=2*i-1) { printf("* "); ++k; } printf("\n"); } return 0; }
Output
Enter number of rows: 5 * * * * * * * * * * * * * * * * * * * * * * * * *
Recommended Programs
Program to find sum of array elementsFinding Largest Element In An Array