27 December, 2012

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 */  





No comments:

Post a Comment

Subscribe To:

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