Header Ads Widget

Ticker

6/recent/ticker-posts

C++ Program to print Number Triangle Coding by Digitalise Data

 

C++ Program to print Number Triangle Coding by Digitalise Data

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 <iostream.h>
  2. #include <conio.h>
  3. void main()  
  4. {  
  5. int i,j,k,l,n;    
  6. cout<<"Enter the Range=";    
  7. cin>>n;    
  8. for(i=1;i<=n;i++)    
  9. {    
  10. for(j=1;j<=n-i;j++)    
  11. {    
  12. cout<<" ";    
  13. }    
  14. for(k=1;k<=i;k++)    
  15. {    
  16. cout<<k;    
  17. }    
  18. for(l=i-1;l>=1;l--)    
  19. {    
  20. cout<<l;    
  21. }    
  22. cout<<"\n";    
  23. }    
  24. getch();  
  25. }  

Output:

 
Enter the Range=5
     1
    121
   12321
  1234321
 123454321  
Enter the Range=6
      1
     121
    2321
   1234321 
  123454321
 12345654321  

Post a Comment

0 Comments