0

The printed result of this binary number(x1,x2) is not what I want.(if I input :1234)Can anyone help me?

#include <stdio.h> int Count_one(int binary_number){ if(binary_number == 0) return 0; return Count_one(binary_number / 10) + binary_number % 10; } long long int HexadecimaltoDecimal(long long int hexadecimal_number, int power){ if(hexadecimal_number == 0) return 0; return HexadecimaltoDecimal(hexadecimal_number / 10, power * 16) + hexadecimal_number % 10 * power; } long long int DecimaltoBinary(long long int n, int power){ if(n == 0) return 0; return DecimaltoBinary(n / 2, power * 10) + n % 2 * power; } int main(){ int time, num, b1, b2; long long int X1, X2; scanf("%d", &time); for(int i = 0;i < time;i++){ scanf("%d",&num); X1 = DecimaltoBinary(num, 1); b1 = Count_one(X1); printf("X1=%lld\n",X1);//I added it myself X2 = DecimaltoBinary(HexadecimaltoDecimal(num, 1), 1); b2 = Count_one(X2); printf("X2=%lld\n", X1);//I added printf("%d %d\n", b1, b2); } return 0; }

29th Dec 2021, 3:22 AM
周志桓
周志桓 - avatar
4 Réponses
+ 1
I would like to help you, could you be more specific? give an example of input and expected output And what is the problem itself, is that it prints "time" times? You could also attach the code directly from the playground next time
29th Dec 2021, 4:07 AM
CGM
CGM - avatar
0
UVA topic is Funny Encryption Method
29th Dec 2021, 2:13 PM
周志桓
周志桓 - avatar
0
When I input 1234 output: X1 = 1421075418//not a binary number X2 = 1421075418//not a binary number 33 27
29th Dec 2021, 2:19 PM
周志桓
周志桓 - avatar
0
Example input: 3 265 111 1234 Expect output: 3 5 6 3 5 5
29th Dec 2021, 2:21 PM
周志桓
周志桓 - avatar