Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions C/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,7 @@
| Program-43 | Program for printing the hollow triangle pattern |
| Program-44 | Program for implementation of the approach |
| Program-45 | Program to illustrate the above given pattern of numbers. |
| Program-46 | Program to convert binary number to decimal |



24 changes: 24 additions & 0 deletions C/program-46/program.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Program to convert binary number to decimal */
#include <stdio.h>
#include <math.h>
int convertBinaryToDecimal(long long n);
int main()
{
long long n;
printf("Enter a binary number: ");
scanf("%lld", &n);
printf("%lld in binary = %d in decimal", n, convertBinaryToDecimal(n));
return 0;
}
int convertBinaryToDecimal(long long n)
{
int decimalNumber = 0, i = 0, remainder;
while (n!=0)
{
remainder = n%10;
n /= 10;
decimalNumber += remainder*pow(2,i);
++i;
}
return decimalNumber;
}