본문 바로가기
프로그램

[C/C++] 문제 : 2차원 배열의 원소 합 구하기

by 오디세이99 2023. 6. 14.
728x90
반응형

 

#include <stdio.h>

double sumElement(double arr[][3], int size1, int size2) {
    double rtn = 0.0;
    for (int i = 0; i < size1; i++) {
        for (int j = 0; j < size2; j++) {
            rtn = rtn + arr[i][j];
        }
    }
    return rtn;
}

void main() {
    double sumValue = 0.0;
    double a[2][3] = {{1.1, 2.1, 3.1}, {4.1, 5.1, 6.1}};
    sumValue = sumElement(a, 2, 3);
    
    printf("모든 원소의 합 : %.2f\n", sumValue);
}

728x90
반응형

댓글