All for Joomla All for Webmasters

C Program to print Number Triangle

Like alphabet triangle, we can write the c program to print the number triangle. The number triangle can be printed in different ways.

Let’s see the c example to print number triangle.

  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. int i,j,k,l,n;
  6. clrscr();
  7. printf(“enter the range=”);
  8. scanf(“%d”,&n);
  9. for(i=1;i<=n;i++)
  10. {
  11. for(j=1;j<=n-i;j++)
  12. {
  13. printf(” “);
  14. }
  15. for(k=1;k<=i;k++)
  16. {
  17. printf(“%d”,k);
  18. }
  19. for(l=i-1;l>=1;l–)
  20. {
  21. printf(“%d”,l);
  22. }
  23. printf(“\n”);
  24. }
  25. getch();
  26. }

Output:

enter the range= 4
   1
  121
 12321
1234321 
enter the range= 7
      1
     121
    12321
   1234321
  123454321
 12345654321
1234567654321
PinIt
submit to reddit

Leave a Reply

Top