In the previous tutorial, I have shared a program to print the star triangle using recursion in c programing language. Like the Star triangle, I am going to share program to display the triangle using the number in c programming language.
Let’s create a program to print the number triangle using the c programming language.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | #include<stdio.h> #include<conio.h> main() { int i,j,k,l,n; clrscr(); printf("Please enter the range:"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=n-i;j++) { printf(" "); } for(k=1;k<=i;k++) { printf("%d",k); } for(l=i-1;l>=1;l--) { printf("%d",l); } printf("\n"); } getch(); } |
Output is:
Please enter the range: 9
1 2 3 4 5 6 7 8 9 | 1 121 12321 1234321 123454321 12345654321 1234567654321 123456787654321 12345678987654321 |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: c program to print triangle, c tutorials, Print Number Triangle in C, triangle program in c