請問代碼哪里出錯了導致失敗
運行結果為:
10:2570101
11:1101
12:0011
13:1011
14:0111
15:1111
16:00001
17:10001
18:01001
19:11001
20:00101
代碼為:
#include<stdio.h>
int main(){
int a=10,b,i=0,r,j=0,count[100];
do{
b=a;
do{
r=b%2;
b=b/2;
i++;
count[i]=r;
}
while(b>0);
printf("%d:",a);
while(j<=i){
printf("%d",count[j]);
j++;
}
a+=1;
printf("\n");
}
while(a<21);
return 0;
}
uj5u.com熱心網友回復:
中間有幾個地方錯了,用這個代碼#include<stdio.h>
int main(){
int a=10,b,i=0,r,j=0,count[100];
do
{
b=a;
do
{
r=b%2;
b=b/2;
count[i]=r;
i++;
}
while(b>0);
printf("%d:",a);
while(j<i)
{
printf("%d",count[j]);
j++;
}
a+=1;
printf("\n");
}while(a<21);
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/63052.html
標籤:新手樂園
上一篇:鏈串%c無法輸出資料問題
下一篇:ACM輸入問題
