Pyramid star pattern program

Pyramid star pattern in c

#include<stdio.h>
#include<conio.h>
void main()
{
	int temp,input;
	printf("Enter the number of rows \n");
	scanf("%d",&input);
	temp=input;
	for(int i=1;i<=input;i++)
	{
		for(int j=1;j<=temp-1;j++)
		{
			printf(" ");
		}
		for(int k=1;k<=2*i-1;k++)
		{
			printf("*");
		}
		temp--;
		printf("\n");
	}
	getch();
}

Output

Enter the number of rows
4
   *
  ***
 *****
*******

Pyramid star pattern in c++

#include<iostream>
#include<conio.h>
using namespace std;
class PyramidStarPattern
{
public:
	void Show(int input)
	{
		int temp;
		temp=input;
		for(int i=1;i<=input;i++)
		{
			for(int j=1;j<=temp-1;j++)
			{
				cout<<" ";
			}
			for(int k=1;k<=2*i-1;k++)
			{
				cout<<"*";
			}
			temp--;
			cout<<"\n";
		}
	}
};
void main()
{
	int input;
	cout<<"Enter the number of rows \n";
	cin>>input;
	PyramidStarPattern p;
	p.Show(input);
	getch();
}

Output

Enter the number of rows
5
    *
   ***
  *****
 *******
*********

Pyramid star pattern in c#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PyramidStarPatternProgram
{
    class PyramidStarPattern
    {
        public void Show(int input)
        {
            int temp;
            temp = input;
            for (int i = 1; i <= input; i++)
            {
                for (int j = 1; j <= temp - 1; j++)
                {
                    Console.Write(" ");
                }
                for (int k = 1; k <= 2 * i - 1; k++)
                {
                    Console.Write("*");
                }
                temp--;
                Console.WriteLine();
            }
        }
        static void Main(string[] args)
        {
            PyramidStarPattern p = new PyramidStarPattern();
            Console.WriteLine("Enter the number of rows \n");
            int input = Convert.ToInt32(Console.ReadLine());
            p.Show(input);
            Console.ReadLine();
        }
    }
}

Output

Enter the number of rows

6
     *
    ***
   *****
  *******
 *********
***********

Pyramid star pattern in java

import java.util.*;
class PyramidStarPattern
{
    public void Show(int input)
    {
        int temp;
        temp = input;
        for (int i = 1; i <= input; i++)
        {
            for (int j = 1; j <= temp - 1; j++)
            {
                System.out.print(" ");
            }
            for (int k = 1; k <= 2 * i - 1; k++)
            {
                System.out.print("*");
            }
            temp--;
            System.out.println();
        }
    }
}
class examples
{
public static void main(String[] args)
	{
	PyramidStarPattern p=new PyramidStarPattern();
	Scanner sc=new Scanner(System.in);
	System.out.println("Enter the number of rows");
	int input=sc.nextInt();
	p.Show(input);
    }
}

Output

Enter the number of rows
7
      *
     ***
    *****
   *******
  *********
 ***********
*************

Write a comment


Name Email Message