mirror of
https://github.moeyy.xyz/https://github.com/TheAlgorithms/C.git
synced 2023-10-11 15:56:24 +08:00
Update Binary to Decimal.c
Improved the readability of the program.
This commit is contained in:
parent
4e7dffefd4
commit
fa53b2fcce
@ -1,17 +1,17 @@
|
||||
#include<stdio.h>
|
||||
#include<conio.h>
|
||||
int main(){
|
||||
int number,decimal_number,temp=1;
|
||||
printf("Enter any binary number= ");
|
||||
scanf("%d",&number);
|
||||
int remainder;
|
||||
while(number>0){
|
||||
|
||||
remainder= number%10;
|
||||
number=number/10;
|
||||
decimal_number+=remainder*temp;
|
||||
temp=temp*2;//used as power of 2
|
||||
|
||||
}
|
||||
printf("%d",decimal_number);
|
||||
int main() {
|
||||
int number, decimal_number, temp=1;
|
||||
printf("Enter any binary number= ");
|
||||
scanf("%d", &number);
|
||||
int remainder;
|
||||
while(number>0) {
|
||||
|
||||
remainder = number%10;
|
||||
number = number/10;
|
||||
decimal_number += remainder*temp;
|
||||
temp = temp*2;//used as power of 2
|
||||
|
||||
}
|
||||
printf("%d",decimal_number);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user