Follow This Blog For more... 😊

C Program to print Hourglass Pattern for n number of lines.[Pattern 24]| Using C language| C Program series 45|

👨‍💻C Program to 
print Hourglass Pattern for n number of lines.[Pattern:24]

Code :

For n number of LINES:

    /*
    C Program to print Hourglass Pattern for n number of lines.[Pattern 24]
    For Example:n=5
   
     # # # # #
      # # # #
       # # #
        # #
         #
        # #
       # # #
      # # # #
     # # # # #
   
    */
   
    #include<stdio.h>
    main()
    {
        printf("C Program to print Hourglass Pattern for n number of lines.[Pattern 24]\n\n");
       
        int i,j,n;
       
        printf("Enter Center of Hourglass at line number:");
        scanf("%d",&n);
        printf("==> Hourglass Pattern.\n");
        for(i=1;i<2*n;i++)
        {
            printf("\n%d\t",i);//here, '\t' used to shift pattern 1 tab space right side

            if(i<=n)
            {
                for(j=1;j<i;j++)
                {
                    printf(" ");
                }
                for(j=n-i+1;j>0;j--)
                {
                    printf("# ");
                }
            }
            else
            {
                  for(j=2*n-1-i;j>0;j--)
                {
                    printf(" ");
                }
                for(j=1;j<=(n-(2*n-1-i));j++)
                {
                    printf("# ");
                }
            }
        }
        printf("\n");  
    }

The output of Code:




👉Click for more C Program series Questions.[Questions list]

Comments

Popular Posts