Q. Write a C program to print the following half-square number triangle C program as :
543212345
4321234
32123
212
1
Ans.
/*c program for half-square number triangle*/
#include<stdio.h>
int main()
{
int num,r,c,n,sp,p;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1,n=num; r<=num; r++,n--)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=r,p=n; c<=num; c++,p--)
printf("%d",p);
for(c=num-r,p=2; c>=1; c--,p++)
printf("%d",p);
printf("\n");
}
getch();
return 0;
}
/******************************************
The output of above program would be:
********************************************/
You might also like to read:
543212345
4321234
32123
212
1
Ans.
/*c program for half-square number triangle*/
#include<stdio.h>
int main()
{
int num,r,c,n,sp,p;
printf("Enter any number : ");
scanf("%d", &num);
for(r=1,n=num; r<=num; r++,n--)
{
for(sp=r; sp>1; sp--)
printf(" ");
for(c=r,p=n; c<=num; c++,p--)
printf("%d",p);
for(c=num-r,p=2; c>=1; c--,p++)
printf("%d",p);
printf("\n");
}
getch();
return 0;
}
/******************************************
The output of above program would be:
********************************************/
Figure : Screen shot for Half-Square Number Triangle C program |
You might also like to read:
Can you do this for letters?
ReplyDeleteDCBABCD
_CBABC_
__BAB___
___A____
Your Required T Shape Character pattern C program at:
Deletehttp://cprogrammingcodes.blogspot.com/2016/01/t-shape-character-pyramid.html