C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL | Indian Shout

You are here: » C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL

C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL


/* Write a C program to convert the given binary number into decimal */

#include <stdio.h>

void main()
{
int   num, bnum, dec = 0, base = 1, rem ;

printf(“Enter a binary number(1s and 0s)\n”);
scanf(“%d”, &num);           /*maximum five digits */

bnum = num;

while( num > 0)
{
rem = num % 10;
dec = dec + rem * base;
num = num / 10 ;
base = base * 2;
}

printf(“The Binary number is = %d\n”, bnum);
printf(“Its decimal equivalent is =%d\n”, dec);

}             /* End of main() */

/*———————————————
Output:
Enter a binary number(1s and 0s)
10101
The Binary number is = 10101
Its decimal equivalent is =21
———————————————-*/

Similar Posts:

 
 
Posted by 0 Responses

Categories:PREPARATION MATERIALS;Tags: , , , , , , , , , ,

Free Email Newsletter

Stay Updates with this Blog. Get Free email newsletter updates..

And then confirm your email subcription

   

No Comment to “C PROGRAM TO CONVERT BINARY NUMBER TO DECIMAL”

  1. No Comment yet. Be the first to comment...
Leave your comment here:

 
Search
Free Email Updates
Get All Latest Updates in Ur e-mail Inbox..

And then confirm your email subcription

Free SMS Alerts
Sponsored Links
Copy Protected by Chetans WP-Copyprotect.