Thursday 30 August 2012

Loop control structure067

Input a binary number  and print the decimal equivalent of that number.

#include <stdio.h>
#include <conio.h>
#include <math.h>
void main ( )
{
             int          md, no, s = 0, d =0;
             clrscr ( );
                                      
             printf ("\n\t\t Enter a binary number......:"); scanf ("%d", & no);
             while ( no > 0 )
             {                                    
                               md = no % 10;
                               no = no / 10;
                               md = md * pow ( 2,d );
                               s = s + md;
                               d++;
             }
                              
             printf ("\n\n\n\t\t The Decimal number =  %d", s);
             getch ( );
}


Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...