# 7์ฅ Programming ํ์ด (1)
289p_1๋ฒ)
#include <stdio.h>
int main()
{
int days[] = { 31,29,31,30,31,30,31,31,30,31,30,31 };
for (int i = 0; i < 12; i++)
{
printf("%d์ผ์ %d์ผ๊น์ง ์์ต๋๋ค.\n", i + 1, days[i]);
}
return 0;
}
289p_2๋ฒ)
#include <stdio.h>
int main()
{
int num;
int array[] = { 0,0,0,0,0,0 };
printf("์
๋ ฅํ ์ ์์ ๊ฐ์: ");
scanf_s("%d", &num);
for (int i = 0; i < num; i++)
{
printf("%d๋ฒ์งธ ์์๋ฅผ ์
๋ ฅํ์์ค: ", i);
scanf_s("%d", &array[i]);
}
for (int i = num - 1; i >= 0; i--)
{
printf("%d ", array[i]);
}
return 0;
}
289p_3๋ฒ)
#include <stdio.h>
int main()
{
int num;
int array[] = { 0,0,0,0,0,0,0,0,0,0 };
int sum = 0;
printf("์
๋ ฅํ ์ ์์ ๊ฐ์: ");
scanf_s("%d", &num);
for (int i = 0; i < num; i++)
{
printf("%d๋ฒ์งธ ์์๋ฅผ ์
๋ ฅํ์์ค: ", i);
scanf_s("%d", &array[i]);
sum += array[i];
}
printf("ํฉ: %d", sum);
return 0;
}
290p_4๋ฒ)
#include <stdio.h>
int main()
{
int array[] = { 0,0,0,0,0 };
int max, min;
for (int i = 0; i < 5; i++)
{
printf("์ ์๋ฅผ ์
๋ ฅํ์์ค: ");
scanf_s("%d", &array[i]);
}
max = array[0];
min = array[0];
for (int a = 1; a < 5; a++)
{
if (array[a] > array[a - 1])
{
max = array[a];
}
if (array[a] < array[a - 1])
{
min = array[a];
}
}
printf("์ต๋๊ฐ: %d, ์ต์๊ฐ: %d", max, min);
return 0;
}
290p_5๋ฒ)
#include <stdio.h>
int main()
{
int score[3][3] = {
{30,10,11},
{40,90,32},
{70,65,56} };
int sum = 0;
for (int i = 0; i < 3; i++)
{
for (int b = 0; b < 3; b++)
{
sum += score[i][b];
}
printf("ํ๋ฒ์ด %d์ธ ํ์์ ํ๊ท ์ ์๋ %d์
๋๋ค.\n", i + 1, sum / 3);
}
return 0;
}
290p_6๋ฒ)
#include <stdio.h>
int main()
{
int array[10][10] = { 0 };
int i, x;
for (int i = 0; i < 10; i++)
{
for (int x = 0; x < 10; x++)
{
array[i][x] = (i + 1) * (x + 1);
}
}
printf("์๊ณ ์ถ์ ๊ตฌ๊ตฌ๋จ์ ์
๋ ฅํ์์ค(์: 9 3): ");
scanf_s("%d %d", &i, &x);
printf("%d X %d = %d", i, x, array[i-1][x-1]);
return 0;
}
291p_7๋ฒ)
#include <stdio.h>
int main()
{
int array1[100][100] = { {0} };
int array2[100][100] = { {0} };
int row = 0, col = 0;
printf("ํ ๊ฐ์: ");
scanf_s("%d", &row);
printf("์ด ๊ฐ์: ");
scanf_s("%d", &col);
printf("์ฒซ ๋ฒ์งธ ํ๋ ฌ ์
๋ ฅ: \n");
for (int i = 0; i < row; i++)
{
for (int k = 0; k < col; k++)
{
scanf_s("%d", &array1[i][k]);
}
}
printf("๋ ๋ฒ์งธ ํ๋ ฌ ์
๋ ฅ: \n");
for (int a = 0; a < row; a++)
{
for (int kk = 0; kk < col; kk++)
{
scanf_s("%d", &array2[a][kk]);
}
}
printf("\n๊ณฑํ ๊ฒฐ๊ณผ: \n");
for (int ii = 0; ii < row; ii++)
{
for (int k = 0; k < col; k++)
{
printf("%d ", array2[ii][k] * array1[ii][k]);
}
printf("\n");
}
return 0;
}
291p_8๋ฒ)
#include <stdio.h>
int main()
{
int array[100][100] = { {0} };
int new_array[100][100] = { {0} };
int row = 0, col = 0;
printf("ํ ๊ฐ์: ");
scanf_s("%d", &row);
printf("์ด ๊ฐ์: ");
scanf_s("%d", &col);
printf("ํ๋ ฌ ์
๋ ฅ: \n");
for (int i = 0; i < row; i++)
{
for (int k = 0; k < col; k++)
{
scanf_s("%d", &array[i][k]);
}
}
printf("\n์ ์น ํ๋ ฌ: \n");
for (int a = 0; a < row; a++)
{
for (int k = 0; k < col; k++)
{
new_array[a][k] = array[k][a];
printf("%d ", new_array[a][k]);
}
printf("\n");
}
return 0;
}