mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 13:31:21 +03:00
Merge pull request #5 from Saumay-Agrawal/patch-2
Update Binary to Decimal.c
This commit is contained in:
commit
ebe0604f26
@ -1,17 +1,17 @@
|
|||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
#include<conio.h>
|
#include<conio.h>
|
||||||
int main(){
|
int main() {
|
||||||
int number,decimal_number,temp=1;
|
int number, decimal_number, temp=1;
|
||||||
printf("Enter any binary number= ");
|
printf("Enter any binary number= ");
|
||||||
scanf("%d",&number);
|
scanf("%d", &number);
|
||||||
int remainder;
|
int remainder;
|
||||||
while(number>0){
|
while(number>0) {
|
||||||
|
|
||||||
remainder= number%10;
|
remainder = number%10;
|
||||||
number=number/10;
|
number = number/10;
|
||||||
decimal_number+=remainder*temp;
|
decimal_number += remainder*temp;
|
||||||
temp=temp*2;//used as power of 2
|
temp = temp*2;//used as power of 2
|
||||||
|
|
||||||
}
|
}
|
||||||
printf("%d",decimal_number);
|
printf("%d",decimal_number);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user