21 March, 2012

C++ Program For Printing Triangle Of Numbers.

This Post Contains A C++ Program For Printing Triangle Of Numbers With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'For-Loop' & 'Nested Loops' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language In A Simple & Easy-To-Understand Way.



# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.



C++ Program For Printing Triangle Of Numbers.

/* Declaration Of Header Files */
# include <iostream.h>
# include <conio.h>

/* Start Of Main Program */
void main()
{
          /* Declaration Of Variables */
          int   i,   j,   num;
          clrscr();

          /* Asking For The Input From User */
          cout << " Enter No. : ";
          cin >>  num;

          /* Source Code For Printing Triangle Of Numbers */
          for ( i  =  1;   i  <=   num;   i++  )
         {
                    for (  j  =  1;  j   <=   i;  j++  )
                   {
                                if (  i  <  10  )
                                      cout << " " << i;
                                else
                                       cout << " " << i;
                   }
                   cout << " \n";
          }
          getch();
}
/* End Of Main Program */



Output  :





No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.