2 like 3 dislike
13.3k views

Write a program to convert a decimal number (<256) to binary. Use +-*/% operations only. Loops are not permitted

寫一個把十進位轉換成二進位數的程式。請使用 +-*/% 運算子,不允許使用迴圈。

Example input:

50

Example output:

110010

 

[Exercise] Coding (C) - asked in Chapter 5: Selection Statements by (12.1k points)
ID: 27668 - Available when: Unlimited - Due to: Unlimited

edited by | 13.3k views

119 Answers

0 like 0 dislike
Hidden content!
* ** * * * * *

int main()

{

int * *


***** * * * ** *** *

b=a%2;
*
****
* * ***
***
*** *
* ***** ** * * *** *** ***
0;



}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
* * * ** * **** ** ** **

int main()

{

int * * * *


* * * * * *** ****

b=a%2;
** **
* *
* ***
*** * **
** * ** * *
**** ** * *** * * ****** ***
* 0;



}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
*** ** ** *****

int main()

{

int ** * ** *


** * ** **** * * *

b=a%2;
* *

** ***
* ****
* * **
* * ** ** * * * ** * ***
** 0;



}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
**** * *** * ** * *

int main()

{

int *** *


*** ** * **** **** * * * * * **

b=a%2;
* **
* ***
* ***
* * * **
*** * ** **
** **** * * ** * **** ** **
***** 0;



}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
** * ** *** * * *

int main()

{

int * * * **


* ** * * * * *****

b=a%2;
* *
* **
* *
***** *
* * ** **
* * ** * ** * * *
* * * 0;



}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
** * * * * * *

int main()

{

int *** ** ***


*** ** * ** **** **

b=a%2;
*
*
**** *
* *
** * **
**** **** * ** * * **
* ** 0;



}
answered by (-254 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()



{
***** * *** * * * *** * **** n,a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
* ****** *** **** * **** * * * * ** * *


** * **** * **** * (n!=0)
** * * * ** * * * * ****** * ** ** * *** ** *
** * * * ** * * ** ****** * ** ***** *** ** * *
****** * **** * *** (n!=0)
****** ******* ** * *** * * * * * ** * **
* * * * * * *** ****** ** **** ** * ** ***

    if (n!=0)
* ** * **** * * *** * * * * *** * *****
* * * * ** ** ** * ** * **** *
* *** * ** * * * * * (n!=0)
* * *** ***** * *** ** ** * * * * * * * * *
* ** ** *** **** * * * ** *** ** ** * ** * **
******* * *** ** ** (n!=0)
** ** * * ** ** * * * * **** * * ** *** * * * *
**** * * * ** *** ** *** * * *** **** * ****
* **** * * *** * (n!=0)
*** * * *** * * ** * ** * **** * ** * ** * * **
* ** ** * * * * * * ** * ***** ***** * **
* **** * *** * ** * ** (n!=0)
****** ** * *** * ** ****** *** **** *
**** * * *** ** * ** * * * *** * * **
** * *** **** * *** * (n!=0)
**** * * ** * ** ** ***** * ** ** * * * * ***
** * * *** ** ** ** * (h)
* ** ** * *** * ** ** * * * ** ** * ** ** ** **** ** **** *
* ****** ** ***** ** (g)
* *** * *** * * * * *** * ** ** **** ** (h==0)
** * ****** * ** ** * * * ** *** ** * * ** * ** *
**** * * * * **** **** * (f)
* * * * ** * * * ** * **** * * (h==0 && g==0)
**** * ** * * ** *** ****** ** ** ********* ** *
* * * ** * * * **** *** (e)
* ** ** **** * * * * * * * *** * * * (h==0 && g==0 && f==0)
** ** ** * ** ** **** * *** * * ******
*** * *** * **** * * (d)
* ** *** * * ** * ** * * ** ***** * * *** *** * (h==0 && g==0 && f==0 && e==0)
******** * * * ***** **** ** ** ** **** *** *** ** ** *
** ***** ******* ** * (c)
* ** ** ** *** *** ** * * * *** * * * * * ****** (h==0 && g==0 && f==0 && e==0 && d==0)
** * ** ** ** * *** ** * * * **** ***** * ***
** ****** ** ** ** ** * (b)
**** ** *** * ** * **** * * * *** (h==0 && g==0 && f==0 && e==0 && d==0 && c==0)
******* ** * ** * *** ** *** ** * *** * * *
** ** ***** ** * * ** * (a)
** * ***** ****** *** * ** ******** * * (h==0 && g==0 && f==0 && e==0 && d==0 && c==0 && b==0)
**** ** * * * ** * * ** * * ******


* ** * *** * * * * * 0;





}
answered by (-249 points)
0 0
Show more...
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()



{
** ** **** *** ***** * n,a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
***** * ** *** *** * * * ** ** **** ** * **


*** ***** ** * *** *** * ** * (n!=0)
** * ** * * *** * *** * ***** *
* * * ** * * * * **** ** * * *** **** *
** * ** *** * * (n!=0)
**** * ** * ** * ** *** * ******** * *
* ** ** *** * * * * * * **** * * * * * ** * *

    if (n!=0)
** * ** ** *** ** *** **** * ***** ** ** *** ** ** *
*** * * * ** *** * **** * ** * ** **
* *** * * * ** * ** (n!=0)
**** ******* ** *** **** ** * * ** *** * * *** * *
**** * ***** * *** * ** * ** * * * * * *
**** * *** * ** ** *** * * (n!=0)
**** ** *** ** ** ** * ** ** * * * **** * * **
******** * *** **** * * ** ***** ** ******* *
** * ** * * * * *** ** ** * (n!=0)
* * * **** * * * ** ** * **** *** ** * **** *** *
** ** ********** ** *** ** ****** * ** * ** *
*** * *** *** * * (n!=0)
* ** * * *** ** * **** *** ** * ****
* ** * *** * * * ** * ** ** * **** * * ****
* * ** * * * * * ** ** ** * (n!=0)
* ** ** ** * ** * **** ****** * **** * ** * *
* * ** * **** * ** * (h)
* ** ** *** *** **** * * * * * *** * * * * * ***** ***** **
** * * * * ** * * * * (g)
** **** *** *** ** * **** * *** ****** ** *** * (h==0)
* *** *** **** * ** * * *** ***** * * *** ** * * *** * *
*** * * *** *** * *** * (f)
** * ** ** * * ** *** * ** ** * **** * * * * (h==0 && g==0)
** ** *** * *** **** ** * * ** * * * * * *** * *
* *** * ** * * *** ***** (e)
* * **** *** **** * * * * * * * **** * * ******* (h==0 && g==0 && f==0)
***** ** * * * * **** ** * * * ** * ***** **
** ** * * ** *** (d)
* * * * * *** ** * * * ** ** * ***** ** * (h==0 && g==0 && f==0 && e==0)
** ** *** ***** **** * * * * ** * * * *
** *** * * * ** ***** * * (c)
* ** * ** ** * *** * ** ** **** ****** * ** ** (h==0 && g==0 && f==0 && e==0 && d==0)
* *** *** * ** ** **** *** *** * * *** * ***
* * * * * * ** * * (b)
*** * * *** * * * * * ** ** **** *** (h==0 && g==0 && f==0 && e==0 && d==0 && c==0)
*** ** * ** * **** ** *** * * * * ** ** * *** *
* * * * ** *** * ** * (a)
* ** * *** * ** * ***** ** * * ** ** (h==0 && g==0 && f==0 && e==0 && d==0 && c==0 && b==0)
****** * * * *** * ******* ** *** * *


* * *** ** *** * * * * * 0;





}
answered by (-249 points)
0 0
Show more...
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()



{
** * ** * ** ** ***** n,a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
* * * ** * *** ** ** * ** * * ** **


** * ** * *** * * * *** (n!=0)
* * * ** ****** * ** * * *** * * *** * *
**** ** **** ** * *** *** ** ** * * *** **
* * * **** * * ** **** * * (n!=0)
* * * * * * * * ********* ** * * * ***
*** *** * * * **** ** *** *** * *** *** * * **** **

    if (n!=0)
* *** * ** ** * *** ** ** ** ** ** * * *
** ** * ** * * *** ** **** ** * ** ****** *
* * * * * * * ** (n!=0)
*** *** * * * * *** * * * * * * * *** * ** * ****
*** * ** * * * ** * * * * **** * * ** * *
** * * * *** *** * (n!=0)
****** * ** * **** * * ** * ** * ** * ** *** **
*** *** * *** * ** ** **** * ***
** * *** * * * *** ****** (n!=0)
*** * * * * **** ** * * * ** ** ** *** * * * *
* ***** ** *** * * * * * ******** ** *
*** ****** * * * * * (n!=0)
* ** * * * *** ** ***** * * * * ** **
*** * *** * * ** * * * ****** ***
**** *** *** ** ** ** **** (n!=0)
* * *** * * * * ** ** * * * ** * * * **
** * * * * ** *** * (h)
* * ********* ** * * ** * * * *** ** ** * ** ** * * * **
* * * * ** ** ***** (g)
*** **** * *** * ** * * * * * *** ******** (h==0)
* ** * * * ** ** * * * ******* * * ** ** * * * * * *
* * ** * ** * * ** * (f)
* * **** ** ** ** * * ** ** *** *** ** (h==0 && g==0)
* * ******** * *** ***** * *** * * ** *** * ** *** *
* ***** *** ** ** * * * * * (e)
* ***** * * * * * ***** * * ** ** *** * * (h==0 && g==0 && f==0)
** * * ** ** *** ** * ** ** * ** * * ** * ***
* *** * * * * ** * (d)
* * * ** **** **** * ** ** * * * ** (h==0 && g==0 && f==0 && e==0)
** * ** ** * * ** ****** * ** ***** *** **
* **** * * ** (c)
* ** **** ** *** * *** **** **** ******* * *** (h==0 && g==0 && f==0 && e==0 && d==0)
* * * * * * * ****** * * * * ** * *
*** * * ** * * **** (b)
* * **** * ** * * **** ** ***** ** * * ** (h==0 && g==0 && f==0 && e==0 && d==0 && c==0)
*** ** *** *** * ** ** * * * * * ** **
**** * * * ** * (a)
****** ** ** * ** ***** *** * ****** (h==0 && g==0 && f==0 && e==0 && d==0 && c==0 && b==0)
** * * * ** * ***** ***** * * * * *


*** ** * * ** ** *** 0;





}
answered by (-249 points)
0 0
Show more...
0 like 0 dislike
Hidden content!
#include <stdio.h>



int main()



{
** * * ** * n,a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0;
** * ** * * *** * **** ** * ** *


* *** * * ** *** *** (n!=0)
* * * ** * * ** * * * *** ** * ** * **
******* * * *** * * * ***** * * * ** ********
* **** ** ** *** * * (n!=0)
* **** ** ** ** ****** * *** ***** ** * * ** *
*** * * ** ** *** * * ** ** * * * *** * *

    if (n!=0)
* * * *** * * *********** * ** * **** ** * ** ** *** ****
**** * * * * * ** ** * * * * *** *** * ** ***
*** * *** *** * * ** * * ***** (n!=0)
* ********* ***** * **** * * *** * * * * ***
* * * ** **** ** *** * ** *** * * * ** * * ** * *
*** ** * * *** **** *** ** ** (n!=0)
*** *** * * * ** * * ** * * * ** ** * * **
*** * ** ********* * * * * * * * ** ***** * *
* * ** *** * * * (n!=0)
*** **** * * * *** *** ** ** * * * **
**** **** * **** ****** **** *** ** *** * * ** ***
* ** * ** * * ***** (n!=0)
* * *** ***** * *** **** * * * * ** *** ** * * ** *
** * * ** * ** * * ****** ** *** * ** * **
* * * **** ** * (n!=0)
*** ** * * * * *** * * ** * **** * * ** * *
**** ***** * ***** * * ** ** (h)
**** * ***** * * * ** * **** ***** **** *** ** * **
* * * * * * * ****** (g)
** ** *** *** * ** ** * ** * * ** ***** ** ** (h==0)
* *** ** ** * ** ****** * ** ***** ** *
* * ** ** * * ** (f)
** * * ** * * * * ** ** **** (h==0 && g==0)
** * * * * * * ** ***** * ** ** * * ******* * *
** * ** ** * * * ** * ** (e)
** ** * *** * * ** * ** * **** ** ** * ** (h==0 && g==0 && f==0)
****** *** * * ** ** * ** * ** * ** **** * *
* ** *** * * * * (d)
* * * ** *** ** **** ** * * *** * * * * (h==0 && g==0 && f==0 && e==0)
* * * * ****** * **** *** ** * * * * ** *
* *** * * * * * **** * *** * (c)
** * * * ** * *** * * * * * * ** * ** * * (h==0 && g==0 && f==0 && e==0 && d==0)
* ***** ** **** **** ** * ** * * ** *** * *
**** * ** ** * ** * *** (b)
******* * ***** * *** * * ** * * ** * ** (h==0 && g==0 && f==0 && e==0 && d==0 && c==0)
* ** *** ** ** * * ** * * ** * ** * *****
***** ******* ** * * ** *** (a)
* *** * * * * ** * * * ** ***** ** * (h==0 && g==0 && f==0 && e==0 && d==0 && c==0 && b==0)
* * ** ***** *** * *** * ** * * *


**** ****** *** * * ** * * * 0;





}
answered by (-249 points)
0 0
Show more...
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.71.255.88
©2016-2025

Related questions

2 like 0 dislike
77 answers
[Exercise] Coding (C) - asked Oct 19, 2017 in Chapter 5: Selection Statements by thopd (12.1k points)
ID: 27667 - Available when: Unlimited - Due to: Unlimited
| 8.9k views
12,783 questions
183,442 answers
172,219 comments
4,824 users