Q. Write a C program to print the following number rhombus pattern design as:
1 1
2 2
3 3
4 4
5 5
4 4
3 3
2 2
1 1
Ans.
/*c program for how to design a number rhombus pattern*/
#include<stdio.h>
int main()
{
int num,r,c,sp,n;
printf("Enter maximum number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
printf("%d", r);
for(sp=r*2; sp>1; sp--)
printf(" ");
printf("%d", r);
printf("\n");
}
for(r=1,n=num-1; r<num; r++,n--)
{
for(sp=r; sp>=1; sp--)
printf(" ");
printf("%d",n);
for(sp=n*2; sp>1; sp--)
printf(" ");
printf("%d", n);
printf("\n");
}
getch();
return 0;
}
You Might Also Like:
1. How to make number rhombus design as:
1
212
32123
4321234
32123
212
1
2. How to make number rhombus design as:
1
121
12321
1234321
12321
121
1
3. How to make a character rhombus design as:
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
4. How to make hourglass star design as:
*********
*******
*****
***
*
***
*****
*******
*********
1 1
2 2
3 3
4 4
5 5
4 4
3 3
2 2
1 1
Ans.
/*c program for how to design a number rhombus pattern*/
#include<stdio.h>
int main()
{
int num,r,c,sp,n;
printf("Enter maximum number : ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>=1; sp--)
printf(" ");
printf("%d", r);
for(sp=r*2; sp>1; sp--)
printf(" ");
printf("%d", r);
printf("\n");
}
for(r=1,n=num-1; r<num; r++,n--)
{
for(sp=r; sp>=1; sp--)
printf(" ");
printf("%d",n);
for(sp=n*2; sp>1; sp--)
printf(" ");
printf("%d", n);
printf("\n");
}
getch();
return 0;
}
/*************************************************************
The output of above number rhombus program:
*************************************************************/
Figure: Screenshot for How To Design A Number Rhombus Pattern C Program |
You Might Also Like:
1. How to make number rhombus design as:
1
212
32123
4321234
32123
212
1
2. How to make number rhombus design as:
1
121
12321
1234321
12321
121
1
3. How to make a character rhombus design as:
A
ABA
ABCBA
ABCDCBA
ABCBA
ABA
A
4. How to make hourglass star design as:
*********
*******
*****
***
*
***
*****
*******
*********
0 komentar:
Post a Comment