Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- long n;
- printf("Nhap so nhi phan: ");
- scanf("%d", &n);
- printf("So nhi phan: %d = %d trong he thap phan.", n, bin2dec(n));
- return 0;
- }
- int bin2dec(long n)
- {
- int result = 0, i = 0, temp;
- while (n!=0)
- {
- temp = n % 10;
- n /= 10;
- result += temp * pow(2, i);
- ++i;
- }
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement