Q. Write a C program to print the following number triangle or number structure:
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
Ans.
/*c program for above number triangle codes*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,num;
printf("Enter loop repeat number(rows): ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<=num-r; sp++)
printf(" "); //it is 2 blank space
for(c=1; c<=2*r-1; c++)
printf(" %d",c);
printf("\n");
}
getch();
return 0;
}
/**************Output**************/
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
Ans.
/*c program for above number triangle codes*/
#include<stdio.h>
#include<conio.h>
int main()
{
int r,c,sp,num;
printf("Enter loop repeat number(rows): ");
scanf("%d", &num);
for(r=1; r<=num; r++)
{
for(sp=1; sp<=num-r; sp++)
printf(" "); //it is 2 blank space
for(c=1; c<=2*r-1; c++)
printf(" %d",c);
printf("\n");
}
getch();
return 0;
}
/**************Output**************/
Screen shot for number triangle C program |
1
ReplyDelete1 4 9
1 4 9 16 25
1 4 9 16 25 36 49
1 4 9 16 25 36 49 64 81
please provide a solution
how to print this program?
ReplyDelete1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6 i need to it
@Farzane Fazil,
DeleteYour required above program source code at:
http://cprogrammingcodes.blogspot.in/2012/02/number-triangle-equal.html
1
ReplyDelete212
32123
4321234
543212345
how to solve it?
Please code for
ReplyDelete0
1 0 1
2 1 0 1 2
3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4
Source code for above number pattern C program as:
Deletehttps://cprogrammingcodes.blogspot.com/2014/08/number-triangle-pattern-c-program.html