Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 # include <stdio.h> # include <conio.h> int scanRow (); int scanColumn (); void inputArray (int, int, int arr[60][60]); void modifyArray (int, int, int arr[60][60], int count [60][60]); void outputTable (int, int, int count [60][60]); int main () { int N,M; int arr [60][60]; int count [60][60]; N=scanRow(); M=scanColumn(); inputArray(N, M, arr); modifyArray(N,M, arr, count ); outputTable(N,M, count); } int scanRow() { int N; printf("enter scope of array\n"); scanf("%d",&N); return N; } int scanColumn() { int M; printf("\n"); scanf("%d",&M); return M; } void inputArray (int N, int M, int arr[60][60]) { int i,j; printf("enter elements of array\n"); for (i = 0; i < N; i++) for (j = 0; j < M; j++) scanf ("%d",& arr[i][j]); } void modifyArray( int N, int M, int arr[60][60], int count [60][60]) { int i, k, j, q; for(i=0; i<N; i++) { for(j=0; j<M; j++) { count [i][j] =0; q = i; for(k=0; k<N; k++) { if (k==j) { q ++; if (q >=N) break; continue; } if (arr[k][q]<0) count [i][j]++; } } } } void outputTable(int N, int M, int count[60][60]) { int index,i,j; printf("|Number|i|j|result|\n"); index=1; for (i = 0; i < N; i++) { for (j = 0; j < M; j++) { printf("|%6d|%d|%d|%6d|\n",index,i,j, count [i][j]); index++; } } getch(); }
- Миниатюры
- 0
- Байт
- 17943 / 11933 / 2479
- Регистрация: 24.12.2010
- Сообщений: 24,043
- 19.09.2018, 22:06[В закладки] [Окно ответа] #10
- По элементам. Должно быть для вашей матрицы
- (0,0) 3 Область (0,0) (0,1) (1,1)
- (0,1) 2 (0,1) (1,1)
- (1,0) 2 (0,0) (1,0) (1,1)
- (1,1) 2 (0,1) (1,1)
- Мне кажется, должно быть так.
- А в моем коде (пост 6) допущена ошибка. Не учитываю элемент arr[i][j].
- CВыделить код
- 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 int count[60][60]; .... void modifyArray( int N, int M, int arr[60][60], count[60][60) { int i, ii, j, q; for(i=0; i<N; i++) { for(j=0; j<M; j++) { count[i][j] =0; q = i; for(ii=0; ii<N; ii++) { if (ii==j) { if (arr[ii][q]<0) count[i][j]++; // Доавочка q ++; // переходим на соседний столбец if (q >=N) break; // такого столбца нет (вылезли за матрицу) continue; } if (arr[ii][q]<0) count[i][j]++; } } } }
- Пройдитесь отладчиком по этому циклу (или выведите индексы анализируемых ментов)
- Но посмотрите внимательней. Стопроцентной точности не гарантирую.
- __________________
- Если я не скажу того, что мог бы сказать, возможно, это не будет сказано никем и никогда.
- 0
- curiousdux99
- 0 / 0 / 0
- Регистрация: 16.09.2018
- Сообщений: 8
- 19.09.2018, 22:59 [ТС][В закладки] [Окно ответа] #11
- Байт,
- Обязательно.
- 0
- Байт
- 17943 / 11933 / 2479
- Регистрация: 24.12.2010
- Сообщений: 24,043
- 20.09.2018, 08:57[В закладки] [Окно ответа] #12
- Тьфу ты! (Это я себе) Какой-то кривой пенечек попался! Для (0,1) область немного другая. Она состоит из одной ячейки (0,1)
- Но код кажется (теперь я уже ни в чем не уверен), правильный.
- __________________
- Если я не ск
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement