29 December, 2012

C++ Program To Find NCR Factor.

This Post Contains A C++ Program To Find NCR Factor With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Functions' 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 To Find NCR Factor.

/* Declaration Of Header Files */
# include < iostream.h >
# inlcude < conio.h >
int fact(int);  // Declaring fact() Function

/* Start Of Main Program */
void main()
{
       int n, c, r;
       clrscr();
       cout << " Enter Values For 'N' & 'R' :- ";
       cin >> n >> r;
       c = fact(n) / ( fact(r) * (fact( n - r ) ) );    // Calling fact() Function
       cout << endl << " NCR Factor Is :- " << c;
       getch();
}
/* End Of Main Program */

/* Defining fact() Function */
int fact( int x )
{
      int i, f = 1;
      for( i = x; i > 0; i-- )
      {
            f = f * i;
       }
       return(f);
}

Output :

Enter Values For 'N' & 'R' :-  6   4

NCR Factor Is :-  15





C++ Program For Printing ASCII Values On Screen/Console.

This Post Contains A C++ Program For Printing ASCII Values On Screen/Console With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'For-loop' 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 ASCII Values On Console.

# include <iostream.h>
# include <conio.h>

void main()
{
        int i;
        clrscr();
        for( i=0;i<256;i++ )
        {
                if ( i != 26 && i != 29 )
                {
                       cout<<i<<"="<<( char )i<<"\t";
                 }
         }
         getch();
}

Output :

The Output Will Be The ASCII Values Of All The Respective Characters, Which Are Valid.







C++ Program For Conversion Of Integers/Numbers Into Words.

This Post Contains A C++ Program For Conversion Of Integers/Numbers Into Words With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'If...else' & 'For-Loop' 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 Conversion Of Integers/Numbers Into Words.

# include < iostream.h >
# include < conio.h >

void main ()
{
    char a[10][10] = { "One" , "Two" , "Three" , "Four" , "Five" , "Six" , "Seven" , "Eight" ,
    "Nine" , "Ten" };
    char b[10][13] = { "Eleven" , "Twelve" , "Thirteen" , "Fourteen" , "Fifteen" , "Sixteen" ,
    "Seventeen" , "Eighteen" , "Nineteen" };
    char c[10][10] = { "Ten" , "Twenty" , "Thirty" , "Forty" , "Fifty" , "Sixty" , "Seventy" ,
    "Eightty" , "Ninty" , "Hundred" };
   
    int r , s, t;
    long n;
    clrscr();

    /* Enter Any No. Below 1 Lakh */

    cout << " Enter Any Number :- ";
    cin >> n;
    if ( n > 9999 )
    {
       r = n / 1000;
           if ( r > 10 && r < 20 )
       {
          r = r % 10;
              cout << b[ r-1 ] << " Thousands ";
       }
       else
       {
          s = r / 10;
              t = r % 10;
              cout << c[ s - 1 ];
              cout << a[ t - 1 ] << " Thousand ";
       }
       n = n % 1000;
    }
    if ( n > 1000 )
    {
       r = n / 1000;
       cout << a[ r - 1 ] << " Thousand ";
       n = n % 1000;
    }
    if ( n > 100 )
    {
       r = n / 100;
       cout << a[ r - 1 ] << " Thousand ";
       n = n % 100;
    }
    if ( n > 10 && n < 20 )
    {
       r = n % 10;
       cout << b[ r - 1 ];
    }
    if ( n > 19 && n <= 100 )
    {
       r = n / 10;
       cout << c[ r - 1 ];
       n = n % 10;
    }
    if ( n > 0 && n <= 10 )
    {
       cout << a[ n - 1 ];
    }
    getch();
}

Output :

/* Enter Any No. Below 1 Lakh */


Enter Any Number :- 1234

One Thousand Two Hundred Thirty Four

Enter Any Number :- 111

One Hundred Eleven



27 December, 2012

C++ Program To Print Even Numbers Upto A User-Specified Range.

This Post Contains A C++ Program To Print Even Numbers Upto A User-Specified Range With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'While-loop' 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 To Print Even Numbers Upto A User-Specified Range.

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

/* Start Of Main Program */
void main()
{
          /* Variable Declaration */
          int  range;
          clrscr();
     
          cout  << "  Enter Range  :  ";
          cin  >>  range;
          int  i  =  1;
          while  (  i  <=  range  )
          {
                    if  (  i  %  2  ==  0  )
                    {
                           cout  <<  i  <<  "  \t  ";
                           i++;
                    }
          }
          getch();
}
/* End Of Main Program */

Output  :

Enter Range  :  6

2   4   6  




C++ Program To Find & Print An Armstrong Number.

This Post Contains A C++ Program To Find & Print An Armstrong Number With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'While-loop' & 'If...else' 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 To Find & Print An Armstrong Number.

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

/* Start Of Main Program */
void main()
{
   /* Declaration Of Variables */
   int Num = 0, s, r, t;
   clrscr();

   cout << " Enter Any Number : ";
   cin >> Num;
   t   =   Num;
   s   =   0;
   while ( Num > 0 )
   {
       r = Num % 10;
       s = s + ( r * r * r );
       Num = Num / 10;
   }
   if ( s == t )
   {
      cout << t << " Is An Armstrong Number.";
   }
   else
   {
      cout << t << " Is Not An Armstrong Number.";
   }
   getch();
}
/* End Of Main Program */

Output :

Enter Any Number : 153

153 Is An Armstrong Number.



C++ Program For Conversion Of Decimal No Into Binary No.

This Post Contains A C++ Program For Conversion Of Decimal No Into Binary No. With Correct Source Code & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'For-Loop' & 'While-Loop' 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 Conversion Of Decimal No Into Binary No.

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

/* Start Of Main Program */
void main()
{
 
   /* Declaration Of Variables */
   int Num, i, j, k, a[20], b[20];
   clrscr();

   /* Asking For The Input From User */
   cout << " Enter Any No. : ";
   cin >> Num;
 
   /* Source Code For Conversion Of Decimal No Into Binary No */
   i = 0;
   while ( Num > 0 )
  {
     a[i] = Num % 2;
     i++;
     Num = Num / 2;
   }
   k = i - 1;
   Cout << "\n\n ";
   for ( j = 0; j < i; j++ )
   {
     b[j] = a[k--];
     cout <<  b[j];
   }
   getch();
}
/* End Of Main Program */  





C++ Program To Find & Print Twin Prime Numbers.

This Post Contains A C++ Program To Find & Print Twin Prime Numbers With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'If...else', 'For-loop' & 'While-loop' 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 To Find & Print Twin Prime Numbers.

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

/* Start Of Main Program */
void main()
{

  
   /* Declaration Of Variables */
   int   i,   j,   k,   r,   t,   a[ 10 ] ;
   clrscr();

   /* Asking For The Input From User */
   cout << " Enter Range   :   ";
   cin >>   r;

   /* Source Code For Finding & Printing Twin Prime Numbers */
   i    =    1 ;  t    =    0 ;
   while   (   i   <=    r    )
   {
              j  =  1 ;  k  =  0 ;
              while   (   j  <=  i   )
              {
                       if   (   i   %   j   ==   0   )
                                k++ ;
                                j++ ;
              }
               if   (   k   ==   2   )
              {
                        a[ t ]  =  i;
                         t++ ;
              } 
              i++ ;
   }
   for    (   i  =  0;    i   <   t;    i++  )
   {
            if   (   a[ i + 1 ]  -  a[ i ]   ==   2    )
                     cout << "\n" <<  a[ i ] << "&" << a[ i + 1 ] << " Are Twin Prime Nos.  " ;
   }  
   getch();
}
/* End Of Main Program */ 

Output :

Enter Range  :  10

3  &  5  Are  Twin  Prime  Nos.

7  &  9  Are  Twin  Prime  Nos. 




C++ Program To Find Prime Factors Of A Number.

This Post Contains A C++ Program To Find Prime Factors Of A Number 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 'If...else' & 'While-Loop' 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.


# Algorithm :

1. Accept any number from user.
2. Initialize i. i=1.
3. Run a loop from 1 to that number to divide the accepted number.
    while( i <= num )
4. if 'i' is a Factor or perfectly divides 'num'.
    if( num % i == 0 )
5. Check whether it is a prime number or not.
    Initialize two variables.
    int j = 1, k = 0;
6. If it is a prime number or k==2.
    Print the Number is a Prime Factor.
7. End if
8. Increment i. i++.
9. End 'while' loop.
10. Stop.


C++ Program To Find Prime Factors Of A Number.

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

/* Start Of Main Program */
void main()
{

    /* Declaration Of Variables */
    int num,  i;
    clrscr();

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

    /* Source Code For Computing Prime Factors Of A Number */
    i  =  1;
    while(  i  <=  num  )
    {
        if( num % i == 0 )
        {
            int j = 1, k = 0;
            while( j  <=  i)
            {
                if( i % j == 0 )
                k++;
                j++;
            }
            if( k == 2 )
            cout  <<  i  << " Is A Prime Factor Of "  <<  num;
            cout  <<  "\n";
        }
        i++;
    }
    getch();
}
/* End Of Main Program */

Output :

Enter Any Number :  60

2 Is A Prime Factor Of 60

3 Is A Prime Factor Of 60

5 Is A Prime Factor Of 60



C++ Program To Find Lowest Number Out Of Three Numbers.

This Post Contains A C++ Program To Find Lowest Number Out Of Three Numbers With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'If...else' 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 To Find Lowest Number Out Of Three Numbers.

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

/* Start Of Main Program */
void main( )
{
     
      /* Declaration Of Variables */
      int  a,  b,  c;
      clrscr();

      /* Asking For The Input From User */
      cout << " Enter Any 3 Value : ";
      cin >>  a  >>  b  >>  c;

      /* Source Code For Computing Lowest Number Out Of Three Numbers */
      if ( a < b && a < c )
      {
             cout  <<  a  <<  " Is The Lowest Number.  ";
      }
      else
      {
             if ( b  <  c )
             {
                      cout  <<  b  <<  " Is The Lowest Number.  ";
             }
             else
             {
                     cout  <<  c  <<  " Is The Lowest Number.  ";    
              }
       }
       getch();
}
/* End Of Main Program */

Output :

Enter Any 3 Values :   12   24   36

12 Is The Lowest Number.  



C++ Program To Find A Factorial Of A Number.

This Post Contains A C++ Program To Find A Factorial Of A Number 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' 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 To Find A Factorial Of A Number.

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

/* Start Of Main Program */
void main()

{

   /* Declaration Of Variables */
   int i, Num = 0, f;

   clrscr();

   /* Asking For The Input From User */
   cout << " Enter Any Number : ";

   cin >> Num;

   /* Source Code For Computing Factorial Of A Number */
   f  =  1;

   for ( i  =  Num;  i  >  0;  i-- )

   {

       f  =  f  *  i;

   }

   cout << " Factorial Of  No. " << Num << " : " << f;

   getch();

}
/* End Of Main Program */

Output :

Enter Any Number  :   6!

Factorial Of  No. 6  :   720



C++ Program For Conversion Of Fahrenheit To Celsius.

This Post Contains A C++ Program For Conversion Of Fahrenheit To Celsius 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 'Conversion' 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 Conversion Of Fahrenheit To Celsius.

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

/* Start Of Main Program */
void main()
{

   /* Declaration Of Variables */
   float c, f;
   clrscr();

   /* Asking For The Input From User */
   cout << " Enter Temp. In Fahrenheit : ";
   cin >> f;
   c  =  (  f  -  32  )  *  5.0  /  9.0;
   cout << " \nTemp. In Celsuis : " << c;
   getch();
}
/* End Of Main Program */ 

Output :

Enter Temp. In Fahrenheit : 110 F
Temp. In Celsius : 43.333332 C

# Click : Here To View 'C++ Program For Conversion Of Celsius To Fahrenheit' Program.



25 March, 2012

C++ Program For Printing A 2D-Array [Two Dimensional] Onto The Screen/Console.

This Post Contains A C++ Program For Printing A 2D-Array [Two Dimensional] Onto The Screen/Console 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 'Arrays', '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 Code Into The Compiler For Direct Result.



C++ Program For Printing A 2D-Array [Two Dimensional] Onto The Screen/Console.

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

/* Start Of Main Program */
void main()
{
   
       /* Declaration Of Variables */
       int  i,  j,  r  =  0,  c  =  0;
       int  a [ 10 ][ 10 ];
       clrscr();

       /* Asking For The Input From User */
       cout  <<  "  Enter Number Of Rows & Columns Of 2D Array [ Matrix ]  :  ";
       cin  >>  r  >>  c ;
      
       //  Accepting Values Of 2D Array [ Matrix ]
       cout  <<  "  Enter  "  <<  r  *  c  <<  "  Values for 2D Array  :  ";
       for  (  i  =  0;  i  <  r;  i++  )
       {
                for  (  j  =  0;  j  <  c;  j++  )
                {
                         cin  >>  a [ i ][ j ];
                }
       }

       // Printing Values Of 2D Array [ Matrix ]
       cout  <<  "  Values Of 2D Array [ Matrix ] Are  :  ";
       for  (  i  =  0;  i  <  r;  i++  )
       {
                cout  <<  " \n ";
                for  (  j  =  0;  j  <  c;  j++  )
                {
                         cin  >>  a [ i ][ j ];
                }
       }
       getch();
}
/* End Of Main Program */ 

Output  :

Enter Number Of Rows & Columns Of 2D Array [ Matrix ]  :  3  3

Enter 9 Values For 2D Array [ Matrix ]  :

1  2  3  4  5  6  7  8  9

Values Of 2D Array [ Matrix ] Are :
1  2  3

4  5  6

7  8  9




C++ Program For Cascading Of Operators.

This Post Contains A C++ Program For Cascading Of Operators 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 'Cascading' 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 Into The Compiler For Direct Result. 


C++ Program For Cascading Of Operators.

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

/* Start Of Main Program */
void main()
{
       
        /* Declaration Of Variables */
        int  a  =  0,  b  =  0;
        clrscr();

        /* Asking For The Input From User */
        cout  <<  "  Enter Values Of A & B  :  ";
        cin  >>  a  >>  b;

        /* Source Code For Cascading Of Operators */
        cout  <<  "  \n The Sum Of  "  <<  a  <<  " & "  <<  b  <<  " : "  <<  a  +  b;
        cout  <<  "  \n The Net Of  "  <<  a  <<  " & "  <<  b  <<  " : "  <<  a  -  b;
        cout  <<  "  \n The Product Of  "  <<  a  <<  " & "  <<  b  <<  " : "  <<  a  *  b;
        if  (  a  >  b  )
        {
               cout  <<  "  \n The Quotient Of  "  <<  a  <<  " Divided By "  <<  b  <<  " : "  <<  a  /  b;
        }
        else
        {
               cout  <<  "  \n The Quotient Of  "  <<  b  <<  " Divided By " <<  a  <<  " : "  <<  b  /  a;
        }
        getch();
}
/* End Of Main Program */ 

Output  :

Enter Values Of A & B  :  2  2

The Sum Of 2 & 2  :  4

The Net Of  2 & 2  :  0

The Product Of 2 & 2  :  4

The Quotient Of 2 Divided By 2  :  1




C++ Program To Find Odd Or Even Number.

This Post Contains A C++ Program To Find Odd Or Even Number With Correct Source Code & Output.
This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'If..else' & 'Nested If...else' 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 Code Into Compiler For Direct Result. 



C++ Program To Find Odd Or Even Number.

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

/* Start Of Main Program */
void main()
{
               
                /* Declaration Of Variables */
                int  Num  =  0;
                clrscr();

                /* Asking For The Input From User */
                cout << "  Enter Any Number :-  ";
                cin >> Num;

                /* Source Code For Computing Odd Or Even Number */
                if  (  Num  ==  0  )
                {
                       cout<< "  Enter Number Other Than Zero. ";
                }
                else
                {
                       if  (  Num  %  2  ==  0  )
                       {
                              cout << Num << "  Is Even Number. ";
                       }
                       else
                       {
                              cout <<  Num << "  Is An Odd Number.  ";
                       }
               }
               getch();
}
/* End Of Main Program */ 

Output  :

Enter Any Number  :-  0

Enter Number Other Than Zero.

Enter Any Number  :-  1

1  Is An Odd Number.

Enter Any Number  :-  2

2  Is Even Number.




21 March, 2012

C++ Program For Printing Pascal's Triangle.

This Post Contains A C++ Program For Printing Pascal's Triangle 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 'If...else', 'For-Loop', 'While-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 Pascal's Triangle.

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

/* Start Of Main Program */
void main()
{
              
               /* Declaration Of Variables */
               int b, p, q, r, x;
               clrscr();

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

               /* Source Code For Computing Pascal's Triangle */
               b = 1;
               q = 0;
               cout << "\n Pascal triangle : \n";
               while ( q < r )
               {
                        for ( p = 30 - 3 * q; p > 0; p-- )
                        cout <<" ";
                        for ( x = 0; x <= q; x++ )
                        {
                                   if ( (x == 0) || (q == 0) )
                                  {
                                             b = 1;
                                   }
                                   else
                                   {
                                              b = ( b * (q-x+1) / x );
                                   }
                                    cout <<"    "<<b;
                         }
                         cout <<"\n";
                         q++;
               }
               getch();
}
/* End Of Main Program */ 



Output  :







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  :





C++ Program To Print Pyramid Of Numbers.

This Post Contains A C++ Program To Print Pyramid Of Numbers With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.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 To Print Pyramid Of Numbers.

/* Declaration Of Header Files */

# include <iostream.h>
# include <conio.h>

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

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

                /* Source Code For Computing Pyramid Of Numbers */
                t  =  1;
                for (  i  = 1;  i  <=  r;  i++  )
                {
                           for ( j=0; j < ( r - i ); j++ )
                          {
                                        cout <<" ";
                          }
                          k = ( i * 2 ) - 1;
                          for (  j  =  0;  j  <  k;  j++  )
                         {
                                        if (  t  >  99  )
                                                cout <<t;
                                        else
                                                if (  t  <  10  )
                                                          cout <<  "  "  <<  t;
                                                else
                                                          cout <<  "  " <<  t;
                                                           t++;
                         }
                         cout <<  "\n\n";
                }
                getch();
}
/* End Of Main Program */ 

Output  :





C++ Program To Print Asterisks Graph.

This Post Contains A C++ Program To Print Asterisks Graph 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 To Print Asterisks Graph.

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

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

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

                /* Source Code For Printing Asterisks Graph */
                for (  i  =  0;  i  <  r;  i++  )
               {
                               cout << " \n ";
                               for (  j  =  0;  j  <=  i;  j++  )
                              {
                                           cout << " * ";
                               }
               }
               getch();
}
/* End Of Main Program */

Ouput :

Enter No. Of Rows :

*
*     *
*     *      *
*     *      *      *
*     *      *      *      *







20 March, 2012

C++ Program For Generating Numbers In The Given Number's Combination.

This Post Contains A C++ Program For Generating Numbers In The Given Number's Combination With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'For-loop', 'While-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 Generating Numbers In The Given Number's Combination.

/* Declaration Of Header Files */

# include <iostream.h>
# include <conio.h>

/* Start Of Main Program */
void main()
{

   /* Declaration Of Variables */
   int   i,   j,   r,   s,   t,    d,   range;
   int p[ 5 ],   q[ 5 ];
   long  n;

   clrscr();

   /* Asking For The Input From User */
   cout << " Enter No. Of Numbers For Combination  :  ";
   cin >> d;
   cout << " Enter Nos. For Combination  :  ";
   for  (  i   =   0;   i   <   d;   i++  )
   {
           cin >> p[ i ];
   }
   cout << " Enter Range : ";
   cin >> range;
  
   /* Source Code For Generating Numbers In The Given Number's Combination */
   for  (  i   =   1;  i   <=   range;   i++   )
   {
             n   =    i;
             s   =   0;
             t   =   0;
     while(  n   >   0  )
     {
              j    =    0;
              r    =   n    %    10;
              t++ ;
             while  (  j    <    d  )
             {
                      if  (  r   ==   p[ j ]  )
                     {
                             s++ ;
                             j++ ;
                     }
             }
             n   =   n   /   10;
     }
     if  (  s   ==   t  )
            cout  <<   i   <<   "  \t  ";
  }
  getch();
}
/* End Of Main Program */ 

Output :

Enter No. Of Numbers For Combination : 2
Enter Nos. For Combination : 1  3
Enter Range : 1000
1  3  11  13  31  33  111   113   131   133  311 313  331  333      




C++ Program Printing Digits Of A Number In An Ascending Ordered Form.

This Post Contains A C++ Program Printing Digits Of A Number In An Ascending Ordered Form With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays', 'for-Loops' & '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 Digits Of A Number In An Ascending Ordered Form.


# include <iostream.h>
# include <conio.h>

void main()
{
                long n, s;
                int    i,    j,    k,    t,    a[ 10 ];
                clrscr();
                cout << " Enter Any Number  :  ";
                cin >> n;
                 j   =   0 ;
                while  (    n    >    0    )
                {
                          i   =   n   %   10;
                         a[ j ]   =   i;
                         j++ ;
                         n   =   n   /   10;
                }
                for   (   i  =  0;   i  <  j;   i++   )
               {
                           for   (   k  =  i+1;    k  <  j;   k++   )
                          {
                                          if   (   a[ i ]   >   a[ k ]   )
                                               t   =   a[ i ] ;
                                               a[ i ]   =   a[ k ] ;
                                               a[ k ]   =   t ;
                           }
                }
                 t   =   j   -   2 ;
                 n   =   s   =   0 ;
                 for   (   i  =  0;   i  <  j;   i++  )
                {
                             s   =   a[ i ] ;
                             for   (   k  =  0;   k  <=  t;   k++   )
                            {
                                         s   =   s   *   10 ;
                                         t-- ;
                                         n   =   n   +   s ;
                            }
                }
                cout << " \n Ordered No.   :   " << n; 
                getch();
}

Output :

Enter Any No.   :   312

Ordered No.   :   123    




C++ Program For Swapping Of Two Integers.

This Post Contains A C++ Program For Swapping Of Two Integers Without Using Third Variable 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 'Swapping' 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 Swapping Of Two Integers.

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

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

   /* Asking For The Input From User */
   cout << "  Enter Any 2 Numbers   :   ";
   cin >>   i >>   j;
   cout << " \n  Before Swapping   :   ";
   cout <<   i <<   j;

 /* Source Code For Computing Swapping Of Two Integers */
   cout << " \n  After Swapping   :   ";
   i   =   i   +   j ;
   j   =   i   -   j ;
   i   =   i   -   j ;
   cout <<   i <<   j;
  
   getch();
}
/* End Of Main Program */

Output :

Enter Any 2 Numbers :  12   21

Before Swapping :  12   21

After Swapping :  21    12    





C++ Program For Conversion Of Decimal No Into Octal No.

This Post Contains A C++ Program For Conversion Of Decimal No Into Octal No With Correct Source Code & Output. This Program Is Written, Compiled & Executed At Turbo C/C++3.0 Compiler & Will Help You To Understand The Concept Of 'For-loop', 'While-loop' & 'If...else' 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 Conversion Of Decimal No Into Octal No.

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

/* Start Of Main Program */
void main()
{

   /* Declaration Of Variables */
   long Num;
   int   r,   q,   o,   a[ 20 ], b[ 20 ];
   clrscr();

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

   /* Source Code For Computing Conversion Of Decimal Into Octal */
   o   =   0;
   while (   Num   >   0   )
   {
     if  (  Num  <  8  )
     {
       a[ o++ ]   =   Num;
       break;
     }
     else
     {
       a[ o++ ]   =   Num   %   8 ;
       Num   =   Num  /  8 ;
     }
   }
   r  =  0;
   for  (  q  =  0 - 1;  q  >=  0;  q--  )
   {
     b[ r++ ]  =  a[ q ] ;
   }

   /* Printing The Output On Console/Screen */
   cout << " \n Octal No.   :   ";
   for  (  q  =  0;  q  <  r;  q++  )
   {
     cout << b[ q ] ;
   }
   getch();
}
/* End Of Main Program */ 




C++ Program For Conversion Of Binary No. Into Decimal No.

This Post Contains A C++ Program For Conversion Of Binary No. Into Decimal No With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC3.0 Compiler & Will Help You To Understand The Concept Of 'Arrays' & 'While-loop' 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 Conversion Of Binary No Into Decimal No.

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

/* Start Of Main Program */
void main()
{
 
   /* Declaration Of Variables */
   int p, q, r, b[20];
   long Num;
   clrscr();
 
   /* Asking For The Input From User */
   cout << " Enter Any Binary Number : ";
   cin >> Num;
 
   /* Source Code For Computing Conversion Of Binary Into Decimal */
   p = 0;
   while ( Num > 0 )
   {
     b[p++] = Num % 10;
     Num = Num / 10;
   }
   q = p - 1;
   r = 0;
   while ( q >= 0 )
   {
     r = r + ( b[q] * pow ( 2 , q ) );
     q--;
   }
   cout << r;
   getch();
}
/* End Of Main Program */     




Subscribe To:

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