PTA 6-8 十进制转换二进制
生活随笔
收集整理的這篇文章主要介紹了
PTA 6-8 十进制转换二进制
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
本題要求實現一個函數,將正整數n轉換為二進制后輸出。
函數接口定義:
void dectobin( int n );函數dectobin應在一行中打印出二進制的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);} }?
總結
以上是生活随笔為你收集整理的PTA 6-8 十进制转换二进制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于借/贷项通知单
- 下一篇: 【2019.4.2最新】error: s