c언어 기초 행렬 연산
적기 귀찮으니 긁어쓰자
[code c
#include <stdio.h>
void main()
{
int ara[4][4]={ { 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}};
int arb[4][4]={ { 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}};
int out[4][4];
int i, j, k;
//더하기
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
out[i][j] = ara[i][j] + arb[i][j];
}
}
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%2d ",out[i][j]);
}
printf("\n");
}
printf("_______________\n");
/**********************곱하기*************/
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
out[i][j]=0;
for(k=0; k<4; k++)
{
out[i][j] = out[i][j] + ara[i][k] * arb[k][j];
}
}
}
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%2d ",out[i][j]);
}
printf("\n");
}
printf("_______________\n");
int a[3] = {1, 2, 3};
int b[3] = {1, 2, 3};
int c[3];
int i;
for (i=0; i<3; i++)
{
c[i] = a[i]*b[i];
printf("%d", c[i]);
}
}
void main()
{
int ara[4][4]={ { 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}};
int arb[4][4]={ { 1, 2, 3, 4},
{ 5, 6, 7, 8},
{ 9, 10, 11, 12},
{13, 14, 15, 16}};
int out[4][4];
int i, j, k;
//더하기
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
out[i][j] = ara[i][j] + arb[i][j];
}
}
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%2d ",out[i][j]);
}
printf("\n");
}
printf("_______________\n");
/**********************곱하기*************/
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
out[i][j]=0;
for(k=0; k<4; k++)
{
out[i][j] = out[i][j] + ara[i][k] * arb[k][j];
}
}
}
for(i=0; i<4; i++)
{
for(j=0; j<4; j++)
{
printf("%2d ",out[i][j]);
}
printf("\n");
}
printf("_______________\n");
int a[3] = {1, 2, 3};
int b[3] = {1, 2, 3};
int c[3];
int i;
for (i=0; i<3; i++)
{
c[i] = a[i]*b[i];
printf("%d", c[i]);
}
}
]
'삽질기초 > SW' 카테고리의 다른 글
C language - matrix (0) | 2012.04.24 |
---|---|
Visual Assist X 1727 (0) | 2010.02.23 |
c# 전역 비트맵. 다시그리기. (0) | 2009.11.04 |
C# 기본 그래픽 (0) | 2009.11.04 |
CString LPSTR WCHAR* (0) | 2009.08.30 |