2 喜歡 3 不喜歡
16.1k 瀏覽

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

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

Example input:

50

Example output:

110010

 

[練習] Coding (C) - 最新提問 分類:Chapter 5: Selection Statements | 用戶: (12.1k 分)
ID: 27668 - 從幾時開始: 無限制 - 到幾時結束: 無限制

修改於 用戶: | 16.1k 瀏覽

119 個回答

0 喜歡 0 不喜歡
內容已隱藏
#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;
}
最新回答 用戶: (-168 分)
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main()
{
** ** ** **** ** * * b1=0,b2=0,b3=0,b4=0,b5=0,b6=0,b7=0,b8=0,d;
*** * ***** * * * * *** * ** * * *** * ****
** ***** ** * * ** ** ** * *** ** * *** ** *
** **** * ****** ** *** * ****** * ** **
** *** * * ** * * *** * *** ** * * * * ** **
* ********* ** ** *** ** * * * * * ** * ** *
* *** *** * *** * * * ****** ** * ** * ****
*** * ** ** ** ** ** **** * ** * ** ** * **
* ** * *** * *** ** * ** * * ** * ** * * ** * **
* * * ** * * *** * ** ** * * ** * * ** *
** *** * * ******* ** ******** * ** * ** * * *
*** **** * * *** *** *** * * * ** * **
* * * ** ** *** ******* *** ** * * * * ** *
*** * **** * ** * ** * ****** ***** * * * *
* * ** *** ** *** *** * * * ** * * * ** ***** *
* ** * * ** * ** * * * ** * ** * ***** ** **
* ** * *** ** * * ** * * *** *** *** **
* ** ****** * ** * ** ** * * * * ** **
* * ** *** * **** **
    {
* * *** * * * * * * *** * **** * * ** *** ** * * *** ****** *** *** * ** *
    }
**** *** * * * * * * ** if(b2!=0)
    {
** *** *** ** ******* * ** ** * * *** * ** ** **** ** *** *** * ** ***
    }
******* ** * * ** * * if(b3!=0)
    {
*** **** * **** * **** * * * *** * ** * ** ***** ** * ***** *** ** ***** **
    }
*** *** * **** * ** if(b4!=0)
    {
** *** * **** ** * ** *** ** ** ** ********* * ***** ** *
    }
* **** * *** ** * * ** ** if(b5!=0)
* *** *** ** * ** ***
* ** *** *** ** **** ** * ******* *** ** ** * * * ** ** * **
* * * * ** * * * *
* ** ** * ***** *** if(b6!=0)
    {
* * ** *** * * * ** *** *** * ** * ** * * * * ** * **** *
    }
*** * * ** ** *** * if(b7!=0)
    {
* *** * * * * * *** * * * * ** * *** * * **** * ****** **
    }
** ** *** * ***
    {
* *** * * ** ***** * **** ** ** * * * ** * **** *
* * * *** * * *** ****

}
最新回答 用戶: (-255 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>

int main ()
{
* * * * * * * ** n,c,k;

* *** *** ****** * * ** * * ***** * an interger in decimal\n");
**** *** * *** * * ** * *** *** *** &n);

* * ** *** * **** **** ***** * * **** * in binary is:\n", n);

** * * * * ***** * ** (c = 4;c>=0; c--)
* * * * ** * * *
* * ** ** *** **** * * **** **** ** *** * ** * *
***** * *** **** * * * *** * * * ** * (k & 1)
*** ***** *** * * * ** ** * ** ** * * * ** *** * **** * *
** * * * ***** ****** * * * *** * ** *
* * **** * * * * ** * * ** * * ** ***** * ** * * ****
*** * * ***** * ** *
* **** ** * * *** * * ****
** **** * * * * * *********** 0;
}
最新回答 用戶: (-167 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include ** ******

int convertTOBINARY(int);

int main()
{
** *** ** *** * ** decimal, binary;
** ** *** * ** * * *** **
**** **** ***** * * * * &decimal);
** ******* **** * * * = ** ** * *** *
* * ** ***** * ** ** ** **** ******* *** * *
* * **** * ****** ** *
* ** * *** *** ** ***** * 0;
}

int convertTOBINARY(int decimal)
{
* * ** *** * ** ** * (decimal == 0)
* ** * * * ** ** *
* * * * * * ****** * * ** * *** * **** ** 0;
**** * * ** *** ** **
* ** * * *** * * * *
*** ** * * * * *
** * * * * ** * **** ** * *** *** ** * (decimal % 2 + 10 * ***** * * * / 2));
** * * * **** * **
}
最新回答 用戶: (-193 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
int main()
{
   int n,a,b,c,d,e,f,g,h,bin;
   scanf ** * *** * * * **
* * * * * * ** * *
** ** *** * * * * ** * *
* ***** ** ** *****
* *** * ** * ** *
**** * * ***
* * *
***** * ** * ** **
******* ** ***
** * ** * ** *** * ***
*** ******** ** ** *
** ** ****** ** ** *
*** ** ** * * *
*** ** ** *** **
* *** * ** ***** * * * ** *
** * * * * ** ** **
* ****** * * ** **** ******** * * * * ** * * *
*** * * * *** *** * **** ** * ** ***
* * **** *** ** * * 0;
}
最新回答 用戶: (-284 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
int main()
{
   int n,a,b,c,d,e,f,g,h,bin;
   scanf ******* ** * **
* ** * ** * * ***
******* *** ** * **
*** * ** * ** * * ****
* * * ** *** *
* * ** * * *** * **
* * * * ** * ***
** * ** * * ** *
** ***** * * ** * ** **
* *** * * **** ** **** *
* ** ***** ** *****
* * ******* ****** **
** *** * * * **
* * * * ** * **
**** * * * *** * **
* ** ** ** **** *
** ** ** ***** * ** *** * * *** * *** *** ***
*** ** * ** *** ** ** * * *
* * * * *** **** ***** ** 0;
}
最新回答 用戶: (-32 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
** * * * * * ****** **
int main()
{
** **** int * * *
* * *** * * **** *** ***
if * * * *
{
*
n/=2;
***
** *
*******
* *
** *
* ***
**
** *
* * *
n/=2;
** *
n/=2;
****
**
* * * **** * *** * * *** * * ** * ** ****** ** * **** ***

}
* 0;}
最新回答 用戶: (-304 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main()
{
* ** * ****** * * * ** * ** * a,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0;
**** * **** * * * ******* ** ** *** * * * **
* * *** *** * * ** (a>=256)
    {
* ** **** ******* ******* ********* ** *** * *** * * ** **** *
    }
* ** ** * * * * *
    {
**** ******* * * ** * * ******** ****** * *
** ** * *** ***** * ** * ** * ** * ** ** * * *
*** ***** ** ** * * ** ****** * * * * * **** ** ***
* ** * ** ** ** ************ * * * ** * **** * ** *** *
** * * * *** * *** *** ** * ***** * **** * ** *** * * * *****
**** * **** *** * * * * * ******* ****** *** *** * *****
**** * **** *** * * * * * ** * * ***** *** * * * *** * *
** * ** *** ** * * * ******* * * *** * ** * * * * *** **
    }
** ** * * * ** ** **** * ** (i==0)
* *** ** * *** ** *
* *** *** * * * * * * * * ** *** * ****** *** *** **
* ** * * * * * * ** * *
* ** * * * * * * ** * if (h==0)
    {
***** * ** ** * * ***** * * ************ * * ** *** ** ** ** ******
    }
** ** ** * **** ***** * ** if (g==0)
******* ******** * **
***** * * ** * * ** **** * ** *** * * * *** ** ** * * * * * ****
* **** * * *** * **** ***
* * *** * ** ** * * * if (f==0)
* *** * * **
* * * * * *** ****** * * **** ***** ** **** * * ** * **** *** ** * ** *
    }
* * * ***** *** * * ** ** if (e==0)
** * *** ** * **
**** * *** *** ** *** * * * *** * * * * * * ***** * ******* **** * **
    }
** * * ** *** *** ** *** if (d==0)
    {
**** ** **** ** ** ****** *** *** ** ** * * ** * * **** *** * ** *
    }
** ******** ** ** ***** * * if (c==0)
* **** **** ** ** ***
* * * ** * *** * * * * **** * * * *** * * * **** **** * * ***
* * * * * * ***
}
最新回答 用戶: (-214 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
int main()
{
*** * *** * ** * * * * a,b=0,c=0,d=0,e=0,f=0,g=0,h=0,i=0;
* ***** *** ** ** * * * * ************* ** * **
* * *** *** * ** * (a>=256)
    {
*** * **** * ****** * ** * * ** * *** * ** * ** ****** * *** ** * * *
    }
** * * * ** * ** * ** **
    {
** * * *** * ***** * *** * * ** ***** *
**** * * ** * * ***** * * * * ** * * * ** *
* ** ** * * * **** * * * *** **** ** **
** ** *** * * *** * ** * ** * **** **** * *
* * * * * * * *** ** * *** * *** **** * * * ***** ** * * **
*** * ** ***** ** ** * **** *** ** * * ****** * * ***** **
* *** * ** ** * ** ** ** * ***** * * *** * ** * * ** * * *
** * * * ** ** * * * ******** * ** ** ** * ** * * * * *
    }
* *** ** * **** * ** (i==0)
* ** * * * ** ** *** ***
* **** **** * * *** ** * ** ** * * * * * * **** * *** * *** * *** *
* *** * * * * ** ** *
** * ** * * ** * * if (h==0)
    {
*** * ********** ** * ** * * * *** *** ** ** ** * * * **** ** ** * *
    }
**** ***** ****** * ** if (g==0)
* * *** ** * * *** *
* * * * * ** ****** **** * * *** ** ** * * *** ******* * * ** * * ** *
** ***** * **** **
**** * **** * ***** *** if (f==0)
* * * ** * * *** * *
* * *** **** ** * ** * * ** ** ** ** * **** * * ** ******* * ** * *** *
    }
* * * *** ****** *** if (e==0)
* * * ** * **** **
* * **** * **** ** ** * * ***** ***** * * ** * * * * * ** *
    }
*** ** * * * **** ** * * if (d==0)
    {
** ** * *** **** ** * *** * **** ** * * ** * ** ** * * ** *
    }
***** *** * ****** * * if (c==0)
** ****** * * ***
* * **** **** * * * * ** ****** * ** ** *** ** * *
** * ** ***** ** * * **
}
最新回答 用戶: (-214 分)
0 0
prog.c: In function 'main':
prog.c:47:18: warning: format '%d' expects a matching 'int' argument [-Wformat=]
         printf("%d,b");
                  ^
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,d1,d2,d3,d4,d5,d6,d7,d8;

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

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

* * ***** ** * * * *** *
* ** ***** ************ ** *** *** ** ** * * *** ** * **** * * ******* ** * **** * *
    else if(d7!=0)
***** * * ***** **** * ** * * * * *** * * * * ***** *** ** ** **** * * *
* * *** ** * ***** ** * if(d6!=0)
*** * * * ** ** * * * * * ** * * * ** ** ** * *** ** ** *****
** * **** ** * * ** if(d5!=0)
* * * * * ******* * * * **** * * ** * * ** *** * * * * * * ******
* ** * ** **** ** *** if(d4!=0)
** *** * * * ** * *** *** * * ***** ** * * * *** * ** ***** ** ** * ***
    else if(d3!=0)
***** ** * * ** ** * ** *** ** * ***** * ** *** ** ***** *** *** *
    else if(d2!=0)
** * ** ** * * * * ** * * ** *** * * *** * ** * * * ** ** **
    else
* * ** **** * * *** * * * ******* * * ** *** * * * * * *****

* **** **** * * * ** 0;
}
最新回答 用戶: (-16 分)
0 0
prog.c: In function 'main':
prog.c:10:8: warning: implicit declaration of function 'pow' [-Wimplicit-function-declaration]
     p1=pow(2,1);
        ^~~
prog.c:10:8: warning: incompatible implicit declaration of built-in function 'pow'
prog.c:10:8: note: include '<math.h>' or provide a declaration of 'pow'
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:108.162.216.62
©2016-2025

相關問題

2 喜歡 0 不喜歡
77 回答
[練習] Coding (C) - 最新提問 10月 19, 2017 分類:Chapter 5: Selection Statements | 用戶: thopd (12.1k 分)
ID: 27667 - 從幾時開始: 無限制 - 到幾時結束: 無限制
| 11.3k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶