fork download
  1. #include <stdio.h>
  2. #define NUM 10
  3.  
  4. int main(void) {
  5. int a[] = {2,4,1,8,10,7,4,6,3,5};
  6. int i,j,key;
  7.  
  8. for(i=0; i<NUM; i++)
  9. printf("%3d",a[i]);
  10. printf("\n");
  11.  
  12. scanf("%d", &key);
  13. // 探索
  14. for(i=0; i<NUM; i++){
  15. if(a[i]==key){
  16. //削除=前に詰める
  17. for(j=i; j<NUM-1; j++) a[j] = a[j+1];
  18. // 末尾要素を0にする
  19. a[9] = 0;
  20. //探索位置を次に進めない
  21. i--;
  22. }
  23. }
  24.  
  25. for(i=0; i<NUM; i++)
  26. printf("%3d",a[i]);
  27. printf("\n");
  28.  
  29. return 0;
  30. }
Success #stdin #stdout 0s 5288KB
stdin
4
stdout
  2  4  1  8 10  7  4  6  3  5
  2  1  8 10  7  6  3  5  0  0