fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. // your code goes here
  5. int i,x;
  6. int data[10]={1,2,4,8,16,32,64,128,256,512};
  7. printf("必要な数字を入力(1~1000)");
  8. scanf("%d",&x);
  9. printf("%d\n",x);
  10. for(i=9;i>=0;i--){
  11. if(data[i]<=x){
  12. printf("%d,",i);
  13. x=x-data[i];
  14. }
  15. }
  16. return 0;
  17. }
  18.  
Success #stdin #stdout 0s 5316KB
stdin
678
stdout
必要な数字を入力(1~1000)678
9,7,5,2,1,