forked from rathoresrikant/HacktoberFestContribute
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added program to convert a 5 digit binary number to decimal
- Loading branch information
1 parent
2bf5215
commit 715be1b
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// binary to decimal converter | ||
// limited to binary with 5 digits | ||
|
||
#include <stdio.h> | ||
|
||
int main() | ||
{ | ||
int a, b, d1, d2, d3, d4, d5; | ||
printf("Enter a 5 digit binary number: \n"); | ||
scanf_s("%d", &a); | ||
d1 = a / 10000; | ||
d2 = a / 1000; | ||
d2 = d2 % 10; | ||
d3 = a / 100; | ||
d3 = d3 % 10; | ||
d4 = a / 10; | ||
d4 = d4 % 10; | ||
d5 = a % 10; | ||
|
||
b = d1 * 16 + d2 * 8 + d3 * 4 + d4 * 2 + d5 * 1; | ||
|
||
printf("%d in binary is %d in decimal\n", a, b); | ||
} | ||
|