[C 프로그래밍] C로 배우는 프로그래밍 기초 14장 이해점검 및 프로그램문제 풀이
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

[C 프로그래밍] C로 배우는 프로그래밍 기초 14장 이해점검 및 프로그램문제 풀이에 대한 보고서 자료입니다.

목차

■ 이해점검 풀이
■ 프로그램 문제 풀이

본문내용

두 이차원 배열의 더하기와 빼기를 수행하는 함수를 만들어, 다음 배열의 연산 결과를 알아보시오.
#include
#define rows 2
#define cols 3
typedef double matrixa[rows][cols];
typedef double matrixb[rows][cols];
typedef double resultc[rows][cols];
void plus(resultc r, matrixa a, matrixb b);
void minus(resultc r, matrixa a, matrixb b);
void display(resultc r, int m);
int main(void)
{
matrixa a = {{4.2, 4.3, 3.8}, {3.7, 1.5, 0.7}};
matrixb b = {{5.2, 2.1, 1.8}, {3.2, 1.4, 2.9}};
resultc r = {0};
display(a, rows);
display(b, rows);
printf("다음은 위 두 행렬의 더하기 결과입니다.\n\n");
plus(r, a, b);
display(r, rows);
printf("다음은 위 두 행렬의 빼기 결과입니다.\n\n");
minus(r, a, b);
display(r, rows);
return 0;
}
void plus(resultc r, matrixa a, matrixb b) {
int i, j, k;
for(i=0; i < rows ; i++) {
for(j=0; j < cols ; j++) {
//r[i][j] = a[i][j] + b[k][j];
*(r[i]+j) = *(a[i]+j) + *(b[i]+j);
}
}
}
void minus(resultc r, matrixa a, matrixb b) {
int i, j, k;
for(i=0 ; i< rows ; i++) {
for(j=0 ; j < cols ; j++) {
//r[i][j] = a[i][j] + b[k][j];
*(r[i]+j) = *(a[i]+j) *(b[i]+j);
}
}
}
void display(resultc r, int m) {
int i, j;
for(i=0; i < m; i++) {
for(j=0; j < cols; j++) {
printf("%8.2f",r[i][j]);
}
printf("\n");
}
printf("\n");
}
5. 프로그램 예제의 두 행렬의 곱 프로그램을 수정하여, 다음 곱을 수행하도록 프로그램을 작성하시오.
#include
#define rows 2
#define cols 3
typedef double matrixa[rows][cols];
typedef double matrixb[cols][rows];
typedef double resultc[rows][rows];
void multiply(resultc r, matrixa a, matrixb b);
void display(resultc r, int m);
int main(void)
{
matrixa a = {{4.2, 4.3, 3.8}, {3.7, 1.5, 0.7}};
matrixb b = {{5.2, 2.1}, {3.2, 1.4}, {1.5, 3.6}};
resultc r = {0};
int i, j;
for(i=0 ; i < rows; i++) {
for(j=0 ; j < cols; j++) {
printf("%8.2f", a[i][j]);
}
printf("\n");
}
printf("\n");
display(b, cols);
printf("다음은 위 두 행렬의 곱 결과입니다.\n\n");
multiply(r, a, b);
display(r, rows);
return 0;
}
void multiply(resultc r, matrixa a, matrixb b) {
int i, j, k;
for(i=0; i < rows ; i++) {
for(j=0; j < rows ; j++) {
for(k=0; k < cols; k++) {
//r[i][j] += a[i][k] * b[k][j];
*(r[i] + j) += *(a[i] + k)* *(b[k] + j);
}
}
}
}
void display(resultc r , int m) {
int i, j;
for(i=0; i for(j=0; j printf("%8.2f", r[i][j]);
}
printf("\n");
}
printf("\n");
}
  • 가격1,000
  • 페이지수9페이지
  • 등록일2008.08.03
  • 저작시기2008.7
  • 파일형식한글(hwp)
  • 자료번호#475264
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니