Number Rhombus Pattern C Program


Q. Write a C program to print the following number rhombus pattern as:

    ********
    ***22***
    **2222**
    *222222*
    22222222
    *222222*
    **2222**
    ***22***
    ********

Ans.

/* c program for number rhombus pattern source code*/
#include<stdio.h>
int main()
{

int num=3,r,c,x,y,z,sp;
printf("******\n");
for(r=1; r<=num; r++)
{
   for(sp=num-r; sp>=1; sp--)
       printf("*");
   for(c=1; c<=r; c++)
       printf("2");
   for(c=r; c>=1; c--)
       printf("2");
   for(c=num-r; c>=1; c--)
       printf("*");

   printf("\n");
}
for(r=1; r<num; r++)
{
   for(sp=r; sp>=1; sp--)
       printf("*");
   for(c=1; c<=(num-r); c++)
       printf("2");
   for(c=num-r; c>=1; c--)
       printf("2");
   for(c=1; c<=r; c++)
       printf("*");
   printf("\n");

}
printf("******\n");
getch();
return 0;
}

Comments

Popular posts from this blog

textcolor in c

wherex in c

traffic light program in c, traffic light simulation