2 like 3 dislike
28.6k 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 | 28.6k 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
prog.c: In function 'main':
prog.c:9:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:11:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:12:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:14:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:15:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:17:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:18:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:20:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:21:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:23:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:24:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:26:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:27:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:29:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
cc1: all warnings being treated as errors
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
prog.c: In function 'main':
prog.c:9:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:11:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:12:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:14:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:15:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:17:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:18:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:20:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:21:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:23:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:24:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:26:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:27:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:29:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
cc1: all warnings being treated as errors
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
prog.c: In function 'main':
prog.c:9:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:11:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:12:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:14:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:15:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:17:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:18:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:20:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:21:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:23:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:24:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:26:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:27:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:29:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
cc1: all warnings being treated as errors
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
prog.c: In function 'main':
prog.c:9:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:11:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:12:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:14:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:15:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:17:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:18:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:20:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:21:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:23:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:24:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:26:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
prog.c:27:5: error: this 'if' clause does not guard... [-Werror=misleading-indentation]
     if (n!=0)
     ^~
prog.c:29:9: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'
         n=n/2;
         ^
cc1: all warnings being treated as errors
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.243.109
©2016-2026

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
| 20.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users