1 #include<stdio.h> 2 int main() 3 { 4 int n,a[20],i,j; 5 while(scanf("%d",&n)!=EOF&&n>0) 6 { 7 8 for(i=0;n/2.0!=0;i++) 9 { 10 a[i]=n%2; 11 n=n/2; 12 } 13 for(j=i-1;j>=0;j--) 14 printf("%d",a[j]); 15 printf(" "); 16 17 } 18 }
1 #include<stdio.h> 2 int main() 3 { 4 int n,a[20],i,j; 5 while(scanf("%d",&n)!=EOF&&n>0) 6 { 7 8 for(i=0;n/2.0!=0;i++) 9 { 10 a[i]=n%2; 11 n=n/2; 12 } 13 for(j=i-1;j>=0;j--) 14 printf("%d",a[j]); 15 printf(" "); 16 17 } 18 }