mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-24 22:39:52 +03:00
b282b95d5b
First printf(): newline character changed from /n to \n
25 lines
488 B
C
25 lines
488 B
C
/**
|
|
* Modified 07/12/2017, Kyler Smith
|
|
*
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
|
|
int main()
|
|
{
|
|
int remainder, number = 0, decimal_number = 0, temp = 1;
|
|
printf("\n Enter any binary number= ");
|
|
scanf("%d", &number);
|
|
|
|
// Iterate over the number until the end.
|
|
while (number > 0)
|
|
{
|
|
remainder = number % 10;
|
|
number = number / 10;
|
|
decimal_number += remainder * temp;
|
|
temp = temp * 2; // used as power of 2
|
|
}
|
|
|
|
printf("%d\n", decimal_number);
|
|
}
|