C Program to print Number Triangle JAVA Training institutes in vizag(JNNC Technologies)


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<stdlib.h>  
  3. int main(){  
  4.   int i,j,k,l,n;    
  5. system("cls");  
  6. printf("enter the range=");    
  7. scanf("%d",&n);    
  8. for(i=1;i<=n;i++)    
  9. {    
  10. for(j=1;j<=n-i;j++)    
  11. {    
  12. printf(" ");    
  13. }    
  14. for(k=1;k<=i;k++)    
  15. {    
  16. printf("%d",k);    
  17. }    
  18. for(l=i-1;l>=1;l--)    
  19. {    
  20. printf("%d",l);    
  21. }    
  22. printf("\n");    
  23. }    
  24. return 0;  
  25. }  
Output:
enter the range= 4
   1
  121
 12321
1234321 
enter the range= 7
      1
     121
    12321
   1234321
  123454321
 12345654321
1234567654321 

Post a Comment

0 Comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();