Q. How to make half rhombus number triangle as:
5
456
34567
2345678
123456789
2345678
34567
456
5
Ans.
/*c program for half rhombus number triangle*/
#include<stdio.h>
int main()
{
int r,c,j,num,n;
printf("Enter Any Number : ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=n; c<=num; c++)
printf("%d", c);
for(c=r, j=num+1; c>1; c--, j++)
printf("%d", j);
printf("\n");
}
for(r=2; r<=num; r++)
{
for(c=r; c<=num; c++)
printf("%d", c);
for(c=num-r, j=num+1; c>=1; c--, j++)
printf("%d", j);
printf("\n");
}
getch();
return 0;
}
You might also like:
5
456
34567
2345678
123456789
2345678
34567
456
5
Ans.
/*c program for half rhombus number triangle*/
#include<stdio.h>
int main()
{
int r,c,j,num,n;
printf("Enter Any Number : ");
scanf("%d", &num);
n=num;
for(r=1; r<=num; r++,n--)
{
for(c=n; c<=num; c++)
printf("%d", c);
for(c=r, j=num+1; c>1; c--, j++)
printf("%d", j);
printf("\n");
}
for(r=2; r<=num; r++)
{
for(c=r; c<=num; c++)
printf("%d", c);
for(c=num-r, j=num+1; c>=1; c--, j++)
printf("%d", j);
printf("\n");
}
getch();
return 0;
}
/********************************************************
The output of above program would be:
********************************************************/
Figure: Screen shot for How To Make Half Rhombus Shape Number Triangle C program |
You might also like:
0 komentar:
Post a Comment