fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. // your code goes here
  6. int a[] = {1, 2, 4};
  7. int aSize = sizeof(a)/sizeof(a[0]);
  8. int **b = (int **)malloc(aSize * sizeof(int*));;
  9. for(int i = 0; i < aSize; i++){
  10. b[i] = (int *)malloc((aSize -1 ) * sizeof(int));
  11. int idx = 0;
  12. for(int j = 0; j < aSize; j++){
  13. if(i == j) continue;
  14. if(a[i] != a[j]) {
  15. b[i][idx++] = a[j];
  16. }
  17. }
  18. }
  19. for(int i = 0; i < aSize; i++){
  20. printf("[ ");
  21. for(int j = 0; j < aSize-1; j++){
  22. printf("%d ", b[i][j]);
  23. }
  24. printf("]\n");
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2300KB
stdin
Standard input is empty
stdout
[ 2 4 ]
[ 1 4 ]
[ 1 2 ]