fork download
  1. #include <stdio.h>
  2.  
  3. void main()
  4. {
  5.  
  6. int data[10] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512};
  7. int request;
  8. int i;
  9.  
  10.  
  11. printf("必要な金額を入力(1〜1000):");
  12. scanf("%d", &request);
  13.  
  14. printf("渡すべき封筒の番号:");
  15.  
  16.  
  17. for (i = 9; i >= 0; i--) {
  18.  
  19. if (request >= data[i]) {
  20. printf("%d ", i);
  21. request = request - data[i];
  22. }
  23. }
  24. printf("\n");
  25. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
必要な金額を入力(1〜1000):渡すべき封筒の番号:9 8 7 6 5 4 3 2 1 0