두 개의 2D 배열로 문제를 해결해야하고 확률 수, 짝수의 합 및 두 배열의 합계와 같은 계산 된 값이 필요합니다. 여러 오류가 발생합니다. 누군가 나를 도울 수 있습니까? 배열을 정의하는 방법이며 함수는 display_odd
이 아닙니다. 왜?2 차원 배열 - 함수
#define DIM 50
#include <stdio.h>
#include <conio.h>
void display_odd(int[][DIM]);
int display_even_sum(int[][DIM], int[][DIM]);
int display_matrix_sum(int[DIM][DIM], int[DIM][DIM]);
void main(){
int x1, x2, y1, y2, x, y, arr1[DIM][DIM], arr2[DIM][DIM], arr[DIM][DIM];
printf("How large do you want the first matrix to be? ('x y') \n");
scanf("%d %d", &x1, &y1);
for (int i = 0; i < x1; i++){
for (int j = 0; j < y1; j++){
printf("A[%d][%d]= ", i + 1, j + 1);
scanf("%d", &arr1[i][j]);
}
}
printf("How large do you want the second matrix to be? ('x y') \n");
scanf("%d %d", &x2, &y2);
for (int i = 0; i < x2; i++){
for (int j = 0; j < y2; j++){
printf("B[%d][%d]= ", i + 1, j + 1);
scanf("%d", &arr2[i][j]);
}
}
if (x1 > x2)
x = x1;
else
x = x2;
if (y1 > y2)
y = y1;
else
y = y2;
//printf("\nThe odd numbers in matrix A are : \n");
//void display_odd(arr1[DIM][DIM]);
//printf("\nThe odd numbers in matrix B are : \n");
//void display_odd(arr2[DIM][DIM]);
printf("\nThe sum of all even elements is : ");
printf("\nThe sum of the initial matrixes is : \n");
arr = display_matrix_sum(arr1[DIM][DIM] ,arr2[DIM][DIM]);
for (int i = 0; i < DIM; i++){
printf("\n");
for (int j = 0; j < DIM; j++)
printf(" %d", arr[i][j]);
}
_getch(); //Wait for it
}
void display_odd(int arr[][DIM]){
for (int i = 0; i < DIM; i++)
for (int j = 0; j < DIM; j++)
if (arr[i][j] % 2 == 1)
printf("[%d][%d]", i, j);
}
int display_even_sum(int arr1[DIM][DIM],int arr2[DIM][DIM]){
int s = 0;
for (int i = 0; i < DIM; i++)
for (int j = 0; j < DIM; j++)
if (arr1[i][j] % 2 == 0)
s += arr1[i][j];
for (int i = 0; i < DIM; i++)
for (int j = 0; j < DIM; j++)
if (arr2[i][j] % 2 == 0)
s += arr2[i][j];
return(s);
}
int display_matrix_sum(int arr1[][DIM],int arr2[][DIM]){
int arr[DIM][DIM];
for (int i = 0; i < DIM; i++)
for (int j = 0; j < DIM; j++)
arr[i][j] = arr1[i][j] + arr2[i][j];
return(arr[DIM][DIM]);
}
해당 C++ 태그에 대해 확실합니까? 나에게 C처럼 보입니다. 이 줄의 – Borgleader
: arr = display_matrix_sum (arr1 [DIM] [DIM], arr2 [DIM] [DIM]); 당신은 int 값을 (display_matrix_sum에서 반환 된) int [] [] 변수에 삽입하려고했습니다. arr이 2 차원 배열로 선언 된 것을 보았습니다. – Ariela
'arr1 [DIM] [DIM]'은'int' (또는 그 인덱스가 유효한 경우)입니다. 배열은 "arr1"이라 불리우므로 함수에 전달해야합니다. – molbdnilo