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

8 comments on “Pyramid Star Pattern”


  • 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();
    }