20 March, 2012

C++ Program To Find Given Number As Binary Or Not.

This Post Contains A C++ Program To Find Given Number As Binary Or Not 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 Given Number As Binary Or Not.

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

/* Start Of Main Program */
void main()
{
 
   /* Declaration Of Variables */
   int r, c;
   long n, t;
   clrscr();
 
   /* Asking For The Input From User */
   cout << " Enter Any Number : ";
   cin >> n;

   /* Source Code For Computing Binary Number */
   t = n;   c = r = 0;
   while (  n  >  0  )
   {
     if ( n % 10 == 0 || n % 10 == 1 )
     {
       c++;
       r++;
       n = n / 10;
     }
   }
   if ( c == r)
     cout << t << " Is Binary ";
   else
     cout << t << " Is Not Binary ";     
   getch();
}
/* End Of Main Program */      




No comments:

Post a Comment

Subscribe To:

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