C Programming

C Programming


Nested Star-Hash Pyramid

Posted: 26 Aug 2013 12:51 AM PDT

Q. Write a C program to print the following star-hash pyramid design:

#####*#####
####*#*####
###*###*###
##*#####*##
#*#######*#
*#########*

/**************************************************************
How To Make Above nested Pyramid C program
***************************************************************
So you can see, there are four types pyramid in above design as:

 #####      *         #####
 ####      *#   *      ####
 ###      *##   #*      ###
 ##      *###   ##*      ##
 #      *####   ###*      #
       *#####   ####* 

Hence, now it is easy to make these above pyramid program. So i recommended to make first above four pyramid program, after making these pyramid design, add these all pyramid in single C program and you are done. :) )
**************************************************************/

Ans.

/*c program for nested star-hash pyramid*/
#include<stdio.h>
int main()
{

 int n=5,r,c;
 for(r=1; r<=6; r++,n--)
 {
   /*first pyramid*/
   for(c=1; c<=n; c++)
     printf(" #");
   /*second pyramid*/
   for(c=1; c<=r; c++)
   {
     if(c==1)
        printf(" *");
     else
        printf(" #");
   }
   /*third pyramid*/
   for(c=r; c>1; c--)
   {
     if(c==2)
        printf(" *");
     else
        printf(" #");
   }
   /*fourth pyramid*/
   for(c=n; c>=1; c--)
        printf(" #");
   printf("\n");
 }
 getch();
 return 0;
}

/*************************************************************
The output of above program would be:
**************************************************************/


Output of nested hash-star pyramid C program
Figure : Screen shot for nested Hash-Star
Pyramid C program



Post a Comment