๋ฐ˜๊ฐ€์›Œ์š”! ํ—ˆ๋ธŒ์ž…๋‹ˆ๋‹ค!

์ €๋Š” ๊ฐœ๋ฐœ์ž๋ฅผ ํ˜„๋Œ€ ์—ฐ๊ธˆ์ˆ ์‚ฌ๋ผ๊ณ  ํ‘œํ˜„ํ•˜๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ๊ฐœ๋ฐœ์„ ๊ณต๋ถ€ํ•˜๋ฉฐ ๋Š๋‚€ ์ ๋“ค๊ณผ ์ด์•ผ๊ธฐ๋ฅผ ๊ธฐ๋กํ•˜๋Š” ๊ณต๊ฐ„์ž…๋‹ˆ๋‹ค.

์•Œ๊ณ ๋ฆฌ์ฆ˜ ํ’€์ด/์ด๋ชจ์ €๋ชจ

[c์–ธ์–ด] ํ–‰๋ ฌ ๊ณฑ์…ˆ ์ž…๋ ฅํ•ด์„œ ์ถœ๋ ฅํ•˜๊ธฐ

mmin.h 2020. 4. 19. 21:07

์•ˆ๋…•ํ•˜์„ธ์š” modernalchemist์˜ H ์ž…๋‹ˆ๋‹ค. 

์˜ค๋Š˜์€ ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ์„ ํ‘œํ˜„ํ•ด๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค. 

๋งŒ์•ฝ ํ–‰๋ ฌ์˜ ๊ณฑ์…ˆ์ด ์–ด๋ ค์šฐ์‹œ๋‹ค๋ฉด ๊ผผ์ˆ˜ํ•™๋‹˜์˜ ๊ฐ•์˜๋ฅผ ๋ณด๊ณ  ์˜ค์‹œ๋Š” ๊ฒƒ์„ ์ถ”์ฒœ ๋“œ๋ฆฝ๋‹ˆ๋‹ค. 

https://www.youtube.com/watch?v=JpSe38UHaos

 

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

// ์ถœ๋ ฅํ•จ์ˆ˜
void printMatrix(int m[][3]) { 
	printf("----- ์ถœ๋ ฅ -----\n");
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			printf("%5d", m[i][j]);
		}
		printf("\n");
	}
}
// ์ž…๋ ฅํ•จ์ˆ˜
void setMatrix(int m[][3]) { 
	int i, j;
	for (i = 0; i < 3; i++) {  
		for (j = 0; j < 3; j++) {
			printf("[%d][%d] : ์ž…๋ ฅ\n", i, j);
			scanf("%d", &m[i][j]);
		}
		if (j != 3)
			printf("mA[%d][%d] : ์ž…๋ ฅ\n", i, j);
	}
}
//๊ณ„์‚ฐ ํ•จ์ˆ˜ 
void calcMatrix(int a[][3],int b[][3], int c[][3]){  
	int k, temp;

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			temp = 0;
			for (k = 0; k < 3; k++) {
				temp += (a[i][k] * b[k][j]);
			}
			c[i][j] = temp;
		}
	}
}
int main(void) {
	int mA[3][3] = { 0 };
	int mB[3][3] = { 0 };
	int mC[3][3] = { 0};

	while (1) {
		int s = NULL;
		printf("ํ”„๋กœ๊ทธ๋žจ์„ ๊ณ„์† ์ง„ํ–‰์‹œํ‚ค๊ณ  ์‹ถ์œผ์‹œ๋ฉด 1์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”\n");
		printf("<<ํ”„๋กœ๊ทธ๋žจ ์ข…๋ฃŒ๋Š” 0์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”>>");
		scanf("%d", &s);
		if (s == 0) break;
		
		printf("mA ์ž…๋ ฅ\n");
		setMatrix(mA);
		printf("mB ์ž…๋ ฅ\n");
		setMatrix(mB);

		printf("mA ์ถœ๋ ฅ\n");
		printMatrix(mA);
		printf("mB ์ถœ๋ ฅ\n");
		printMatrix(mB);
		printf("mC ๊ณ„์‚ฐ\n");
		calcMatrix(mA, mB, mC);

		printf("mC ์ถœ๋ ฅ\n");
		printMatrix(mC);
	}
	return 0;
}

์ฝ”๋“œ ๊ด€๋ จํ•ด์„œ ๊ถ๊ธˆํ•˜์‹  ์ ์ด๋‚˜ ์ˆ˜์ •์‚ฌํ•ญ์ด ์žˆ๋‹ค๋ฉด ๋Œ“๊ธ€๋กœ ๋‚จ๊ฒจ์ฃผ์‹œ๋ฉด ๊ฐ์‚ฌํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.