PTA 6-8 十进制转换二进制
生活随笔
收集整理的這篇文章主要介紹了
PTA 6-8 十进制转换二进制
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
本題要求實(shí)現(xiàn)一個(gè)函數(shù),將正整數(shù)n轉(zhuǎn)換為二進(jìn)制后輸出。
函數(shù)接口定義:
void dectobin( int n );函數(shù)dectobin應(yīng)在一行中打印出二進(jìn)制的n。建議用遞歸實(shí)現(xiàn)。
裁判測試程序樣例:
#include <stdio.h>void dectobin( int n );int main() {int n;scanf("%d", &n);dectobin(n);return 0; }/* 你的代碼將被嵌在這里 */輸入樣例:
10輸出樣例:
1010 void dectobin( int n ){int res=0;if(n==0)printf("0");else if(n==1)printf("1");else{dectobin(n/2);res=n%2;printf("%d",res);} }?
總結(jié)
以上是生活随笔為你收集整理的PTA 6-8 十进制转换二进制的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于借/贷项通知单
- 下一篇: 【2019.4.2最新】error: s