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.



Subscribe To:

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