This commit is contained in:
2025-02-04 08:13:18 +03:00
parent bb35fb2db6
commit 8e36a1a11c
6 changed files with 142 additions and 2 deletions

View File

@ -0,0 +1,26 @@
#include <stdio.h>
int main(void) {
int i;
puts("Enter binary!");
scanf("%d", &i);
int t = i;
int final = 0, power = 1;
while (t > 0) {
if(t % 10 == 1) {
final = power + final;
t = t / 10;
} else if (t % 10 == 0) {
t = t / 10;
} else {
puts("NOT BINARY!");
return 1;
}
power = 2 * power;
}
printf("Decimal: %d, Binary: %d\n", final, i);
return 0;
}