Pyramid Star Pattern

    *
   ***
  *****
 *******
*********

Write a universal program to print star pattern with n as input.

Write the Code in different languages in the comments, we will add this program in the comments section later

11 comments on “Pyramid Star Pattern”


  • Amit

    #include
    using namespace std;
    int main()
    {
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    for(int j=1;j<=(n-i);j++)
    {
    cout<<" ";
    }
    for(int k=1;k<=(2*i-1);k++)
    {
    cout<<"*";
    }
    cout<<"\n";
    }
    return 0;
    }


  • Sneha

    package No_Pattern;

    public class Pattern_star {

    public static void main(String[] args) {
    // TODO Auto-generated method stub
    for(int i=5;i>0;i–){

    for(int j=0;j=i;k–){
    System.out.print(“* “);
    }

    System.out.println();
    }
    }

    }


  • Jayadeep

    python code
    n=int(input())
    k=2*n-2
    for i in range(1,n+1):
    for j in range(k):
    print(end=” “)
    k=k-2
    for l in range(2*i-1):
    print(“*”,end=” “)
    print()


  • Alok

    #include
    using namespace std;

    int main() {
    int n;
    cin>>n;

    int stars=1;
    int total=(n*2)-1;

    for(int i=0; i<n; i++)
    {
    int spaces=(total-stars)/2;
    for(int j=0; j<spaces; j++)
    cout<<" ";
    for(int j=0; j<stars; j++)
    cout<<"*";
    for(int j=0; j<spaces; j++)
    cout<<" ";
    cout<<endl;
    stars+=2;
    }
    return 0;
    }


  • ishita

    iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii

    loooooooooooooooveeeeeeeeeeeeeeeeuuuuuuuuuuuuuuuuuuuuuuuuu


  • Harsha

    In C++ :

    #include
    using namespace std;
    int main()
    {
    int i,j,n;
    cin>>n;
    for(i=0;i<n;i++)
    {
    for(j=0;j<n-i;j++)
    {
    cout<<" ";
    }
    for(int k=0;k<2*i+1;k++)
    {

    cout<<"*";
    }
    cout<<endl;
    }

    return 0;
    }


  • ajit

    in java::
    import java.util.Scanner;

    public class Main
    {
    public static void main(String args[])
    {
    Scanner sc = new Scanner(System.in);
    System.out.println(“Enter the number of lines to print pyramid pattern”);
    int n = sc.nextInt();
    for(int i=1;i=i;j–)
    {
    System.out.print(” “);
    }
    for(int k =i;k>=1;k–)
    {
    System.out.print(“*”);
    }
    for(int l = 2;l<=i;l++)
    {
    System.out.print("*");
    }
    for(int m=i;m<=(n-1);m++)
    {
    System.out.print(" ");
    }

    System.out.println();
    }

    }

    }


  • Sabiya Tabassum

    #include

    int main()
    {
    int n,i,j;
    scanf(“%d”,&n);
    for(i=1;i<n;i++)
    {
    for(j=i;j<n;j++){
    printf(" ");}
    for(j=1;j<=2*i-1;j++)
    {
    printf("*");
    }
    printf("\n");
    }
    }


  • Saima Afreen

    #include
    #include
    int main()
    {
    int i,j,s,n;
    scanf(“%d”,&n);
    for(i=0;i=i;s–)
    {
    printf(” “);
    }
    for(j=0;j<(2*i+1);j++)
    {
    printf("*");
    }
    printf("\n");
    }
    getch();
    }