Long time no see

This commit is contained in:
2026-02-21 10:47:00 +07:00
parent 0d54fe176e
commit b7df98a55c
198 changed files with 3249 additions and 1 deletions
+41
View File
@@ -0,0 +1,41 @@
// Разработайте функцию, выполняющую преобразование строки
//с однобайтовым двоичным числом в целое десятичное число.
#include <stdio.h>
int main(){
char input;
long long int binary = 0;
int decimal = 0;
// Input
{
printf("Input binary: ");
while((input=getchar())>='0' && input <= '1'){
binary = (binary * 10) + (input - '0');
}
if(input != '\n' && input != EOF && input != 4){
printf("Err, handle char not a 1 or 0");
return 1;
}
}
// __
// Func
int base = 1;// base = (2**n)
long long int bin = binary;
while (binary) {
int last = binary % 10;
binary = binary / 10;
decimal += last * base;
base = base * 2;
}
// __
// Output
printf("binary(%lld) = decimal(%d)",bin,decimal);
return 0;
// __
}
BIN
View File
Binary file not shown.