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 Turbo C/C++3.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 <stdio.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 */
printf(" \n Enter Any Number : ");
scanf( "%d", &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)
printf(" \n %d Is Binary ", t);
else
printf(" \n %d Is Not Binary ", t);
getch();
}
/* End Of Main Program */
# 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 <stdio.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 */
printf(" \n Enter Any Number : ");
scanf( "%d", &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)
printf(" \n %d Is Binary ", t);
else
printf(" \n %d Is Not Binary ", t);
getch();
}
/* End Of Main Program */
No comments:
Post a Comment