Q. Write a C program to print the following number triangle or structure:
1
21
321
4321
54321
Ans.
/*c program code for number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>0; sp--)
printf(" ");
for(c=r; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/****************Output**************/
1
21
321
4321
54321
Ans.
/*c program code for number pyramid*/
#include<stdio.h>
int main()
{
int num,r,c,sp;
printf("Enter number of rows: ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=num-r; sp>0; sp--)
printf(" ");
for(c=r; c>=1; c--)
printf("%d",c);
printf("\n");
}
getch();
return 0;
}
/****************Output**************/
Screen shot for number triangle C program |
sir how can we do this
ReplyDelete*****5
****54
***543
**5432
*54321
#include
Delete#include
void main()
{
int n,r,c,s;
clrscr();
printf("enter loop repeat number");
scanf("%d",&n);
for(r=n;r>=1;r--)
{
for(s=1;s<=r;s++)
printf("*");
for(c=n;c>=r;c--)
printf("%d",c);
printf("\n");
}
getch();
}
1
ReplyDelete2 1 2
3 2 1 2 3
4 3 2 12 3 4 iwant java code for this triangle
****1
ReplyDelete***21
**321
*4321
54321
i want in php code
wat is the c code for_
ReplyDelete1
21
321
4321
54321
@ Saks#!
DeleteYour required number triangle pyramid C program source code at:
http://cprogrammingcodes.blogspot.com/2011/09/14design-numbers-tringle-pyramid.html
5 4 3 2 1
ReplyDelete4 3 2 1
3 2 1
2 1
1
@Sagar Kacharia,
DeleteNumber Triangle Pyramid Pattern C program source code :
http://cprogrammingcodes.blogspot.com/2011/09/13design-numbers-tringle-pyramid.html
could you do this?
ReplyDelete01234
10123
21012
32101
43210
#Alit
DeleteThanks for comments, your required number triangle C program source code as:
#include"stdio.h"
int main()
{
int r,c,num=5;
for(r=0; r=0; c--)
printf(" %d",c);
for(c=1; c<num-r; c++)
printf(" %d",c);
printf("\n");
}
return 0;
}
/***** OUTPUT******/
01234
10123
21012
32101
43210