C Programming

C Programming


Star-Zero Nested Pattern

Posted: 21 Sep 2013 10:50 PM PDT

Q. Write a C program to print the following star-zero nested pattern pyramid as:

*000*000*
0*00*00*0
00*0*0*00
000***000

Ans.

How to make above star-zero nested pattern:

*000*000*
0*00*00*0
00*0*0*00
000***000

In above star-zero nested pattern, there are 4 loops(each loop have different color), so before you making above pyramid, you should make first individual each loop, after making all loop, join them.
That's done.

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

 int num,n,r,c;
 printf("Enter number of rows : ");
 scanf("%d", &num);
 n=num;
 for(r=1; r<=num; r++,n--)
 {
   for(c=1; c<r; c++)
      printf("0");
   for(c=1; c<=n; c++)
   {
      if(c==1)
         printf("*");
      else
         printf("0");
   }
   printf("*");
   for(c=1; c<n; c++)
      printf("0");
   for(c=1; c<=r; c++)
   {
      if(c==1)
         printf("*");
      else
         printf("0");
   }
   printf("\n");
 }
 getch();
 return 0;
}

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


Output of Star-Zero Nested Pattern C program
Figure: Screen-shot for Star-Zero Nested Pattern C program



Post a Comment