Write a program to convert a decimal number (<256) to binary. Use +-*/% operations only. Loops are not permitted
寫一個把十進位轉換成二進位數的程式。請使用 +-*/% 運算子,不允許使用迴圈。
Example input:
50
Example output:
110010
Hidden content!#include ** * * * * * * int main(){ * * * * **** ** * ** * * * number, n, remainder, binary = 0, place = 1;* *** ** * * ** * **** * * * * a number * * *** * * * * * * ** *** * * * * * * * * * * ** * * * * * * = number;* *** * * **** * *** * *** ** (n > 0) * * * *** * ** **** * * * * * * * * ** ** * ** ** * * * * * * * * ** * = n % 2;* * * * * * * * * * * ** * * * * * ** * ** * *** ** * * ** * ** += remainder * place;** * *** * * ** * * * * * *** * * *** * * * * * ** *= 10; * * * * ** * * ** * * ** * * * * * ** * /= 2; * ** * * * ** * ** * * ** * * ** ** * * ** * * * * * * * * * **** * * * * * equivalent of %d is * * * ** number, binary); * * ** **** * *** * 0;}
Hidden content!#include<stdio.h>int main(){* ** ** *** *** * * ** * b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0,d;