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;
}
You might also like to read:
********
***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;
}
/*************************************
The output of above Number Rhombus Pattern C Program would be:
**************************************/
Figure: Screen shot for Number Rhombus Pattern C Program |
You might also like to read:
We can also write the above program with less number of variables na
ReplyDeleteThanks for program
ReplyDelete