fork download
  1. #include <stdio.h>
  2. #define MAXIMUM 100
  3. int main(){
  4. int arr[MAXIMUM][MAXIMUM];
  5. int otv[MAXIMUM][MAXIMUM];
  6. int n, m, k, count, all_even, new_row, index;
  7. int i, j;
  8.  
  9. printf("enter height and lenght: ");
  10. scanf("%i %i", &n, &m);
  11.  
  12. /*Input of elements of the start array*/
  13. for (i = 0; i < n; i++) {
  14. printf("enter %d elements of the %d of %d lines: ", m, i+1, n);
  15. index = 0;
  16. all_even = 1;
  17. while (all_even == 1 && index < m && scanf("%d", &k) == 1) {
  18. arr[i][index] = k;
  19. index++;
  20. if (k < 0){
  21. all_even = 0;
  22. }
  23. }
  24. }
  25.  
  26. printf("\n");
  27.  
  28. /*Determining the size of a final array*/
  29. count = 0;
  30. for (i = 0; i < n; i++) {
  31. all_even = 1;
  32. for (j = 0; j < m; j++) {
  33. if (arr[i][j] % 2 != 0) {
  34. all_even = 0;
  35. }
  36. }
  37. if (all_even) {
  38. count++;
  39. }
  40. }
  41.  
  42. /*Enter final array*/
  43. new_row = 0;
  44. for (i = 0; i < n; i++) {
  45. all_even = 1;
  46. for (j = 0; j < m; j++) {
  47. if (arr[i][j] % 2 != 0) {
  48. all_even = 0;
  49. }
  50. }
  51. if (all_even) {
  52. for (j = 0; j < m; j++) {
  53. otv[j][new_row] = arr[i][j];
  54. }
  55. new_row++;
  56. }
  57. }
  58.  
  59. /*Output start array*/
  60. printf("start array:\n");
  61. for (i = 0; i < n; i++) {
  62. for (j = 0; j < m; j++) {
  63. printf("%d ", arr[i][j]);
  64. }
  65. printf("\n");
  66. }
  67.  
  68. printf("\n");
  69.  
  70. /*Output final array*/
  71. printf("final array:\n");
  72. for (i = 0; i < m; i++) {
  73. for (j = 0; j < count; j++) {
  74. printf("%d ", otv[i][j]);
  75. }
  76. printf("\n");
  77. }
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
enter height and lenght: 
start array:

final array: