// 3x3 행렬을 나타내는 두 개의 2차원 배열 s와 d를 인수로 받아서
// s의 전치 행렬을 d에 저장하는 다음 함수를 작성하고 이 함수의 동작을 확인하시오.
// 전치 행렬은 행렬의 행과 열을 교환한 행렬이다.
// void transpose(int s[3][3], int d[3][3])

#include <stdio.h>

사용자 삽입 이미지

void transpose(int s[3][3], int d[3][3]);

main(void){

 int from[3][3] = {
  1,2,3,
  4,5,6,
  7,8,9
 };

 int to[3][3];
 int k, l;

 transpose(from,to);

 for(k=0; k<3; k++){
  for(l=0; l<3; l++)
   printf("%d ", to[k][l]);
  printf("\n");
 }
 return 0;
}

void transpose(int s[3][3], int d[3][3]){
// 1 2 3   1 4 7
// 4 5 6    ->  2 5 8
// 7 8 9   3 6 9

 int i,j;

 for(i=0; i<3; i++){
  for(j=0; j<3; j++)
   d[j][i] = s[i][j];
 }
}

<문자열 길이에 관한>
#include <stdio.h>
#include <string.h>
#define praise "My sakes, that's a grand name!"

int main(void)
{
 char name[40];

 printf("What's your name? \n");
 scanf("%s", name);
 printf("Hello, %s. %s\n", name, praise);
 printf("Your name of %d letters occupies %d memory cells. \n", strlen(name), sizeof name);
 printf("The phrase of PRAISE has %d letters ", strlen(praise));
 printf("and occupies %d memory cells. \n", sizeof praise);
}
== run ==
What's your name?
Sungjo (Enter)
Hello, Sungjo. My sakes, that's a grand name!
Your name of 6 letters occupies 40 memory cells.
The phrase of PRAISE has 30 letters and occupies 31 memory cells.
Press any key to continue
 

by Joe & Soohy 2007. 1. 16. 00:32