fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. int i,a[]={3,5,2,4,1,9,7,6,0,8};
  5. int temp; //一時的に値をいれる
  6. //a[0]とa[3]の入れ替え
  7. temp = a[0];
  8. a[0] = a[3];
  9. a[3] = temp;
  10. //a[3]とa[5]の入れ替え
  11. temp = a[3];
  12. a[3] = a[5];
  13. a[5] = temp;
  14. //a[5]とa[8]の入れ替え
  15. temp = a[5];
  16. a[5] = a[8];
  17. a[8] = temp;
  18. //3回入れ替えたあとの表示
  19. printf("3回入れ替えた後の配列:\n");
  20. for(i=0;i<10;i++){
  21. printf("%d ",a[i]);
  22. }
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
3回入れ替えた後の配列:
4 5 2 9 1 0 7 6 3 8