# 7์ฅ Programming ํ์ด (2)
291p_9๋ฒ)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int most, num;
int array[10] = { 0 };
srand(time(NULL));
for (int i = 0; i < 100; i++)
{
num = rand() % 10;
for (int k = 0; k < 10; k++)
{
if (num == k)
{
array[k]++;
}
}
}
for (int a = 1; a < 10; a++)
{
if (array[a] > array[a - 1])
{
most = a;
}
}
printf("๊ฐ์ฅ ๋ง์ด ์์ฑ๋ ์: %d", most);
return 0;
}
292p_10๋ฒ)
#include<stdio.h>
#include <stdlib.h>
int main()
{
int array[6] = { 0 };
srand(time(NULL));
for (int i = 0; i < 60000; i++)
{
int m = rand() % 6;
array[m]++;
}
printf("=============================\n");
printf("์ฃผ์ฌ์๋ฉด ๋น๋\n");
printf("=============================\n");
for (int i = 0; i < 6; i++)
{
printf(" %d %d\n", i + 1, array[i]);
}
return 0;
}
292p_11๋ฒ)
#include <stdio.h>
int main()
{
int num;
int array[100];
int new[100] = { 0 };
printf("์
๋ ฅํ ์ ์์ ๊ฐ์(100๊ฐ ์ด๋ด๋ก): ");
scanf_s("%d", &num);
for (int i = 0; i < num; i++)
{
printf("%d๋ฒ์งธ ์์๋ฅผ ์
๋ ฅํ์์ค: ", i);
scanf_s("%d", &array[i]);
}
for (int i = 0; i < num; i++)
{
new[array[i]] += 1;
}
printf("\n");
for (int a = 0; a <= num; a++)
{
if (new[a] != 0)
{
printf("%d ๊ฐ์ %d๋ฒ ๋ฑ์ฅ\n", a, new[a]);
}
}
return 0;
}
292p_12๋ฒ)
#include <stdio.h>
int main()
{
int num, del;
int array[100];
printf("์
๋ ฅํ ์ ์์ ๊ฐ์(100๊ฐ ์ด๋ด๋ก): ");
scanf_s("%d", &num);
for (int i = 0; i < num; i++)
{
printf("%d๋ฒ์งธ ์์๋ฅผ ์
๋ ฅํ์์ค: ", i);
scanf_s("%d", &array[i]);
}
printf("\n์ญ์ ํ ์์น: ");
scanf_s("%d", &del);
for (int i = 0; i < num; i++)
{
if (i == del)
{
for (int k = del; k < num; k++)
{
array[k] = array[k + 1];
}
}
}
printf("์๋ก์ด ๋ฐฐ์ด: ");
for (int i = 0; i < num - 1; i++)
{
printf("%d ", array[i]);
}
return 0;
}
293p_13๋ฒ)
#include<stdio.h>
int main()
{
int seat[10] = { 0 };
int reg;
char book;
for(;;)
{
printf("์ข์์ ์์ฝํ์๊ฒ ์ต๋๊น?(y ๋๋n): ");
scanf_s(" %c", &book);
if ('y' == book)
{
printf("๋ช๋ฒ์งธ ์ข์์ ์์ฝํ์๊ฒ ์ต๋๊น?: ");
scanf_s("%d", ®);
if (seat[reg - 1] == 1)
{
printf("์ด๋ฏธ ์์ฝ๋ ์ข์์
๋๋ค.\n");
}
else
{
seat[reg - 1] = 1;
printf("์์ฝ๋์์ต๋๋ค.\n");
printf("---------------------------------\n");
printf(" 1 2 3 4 5 6 7 8 9 10\n");
printf("---------------------------------\n");
for (int i = 0; i < 10; i++)
{
printf(" %d", seat[i]);
}
printf("\n");
}
}
else
{
break;
}
}
return 0;
}
293p_14๋ฒ)
#include <stdio.h>
int main()
{
double average = 0.0;
double v = 0.0; // v/n์ ํ์คํธ์ฐจ
double sum = 0.0;
double array[5] = { 0.0 };
for (int i = 0; i < 5; i++)
{
printf("์ค์๋ฅผ ์
๋ ฅํ์์ค: ");
scanf_s("%lf", &array[i]);
sum += array[i];
}
for (int k = 0; k < 5; k++)
{
v += ((array[k] - sum) * (array[k] - sum));
}
printf("\nํ๊ท : %.5lf\n", sum / 5.0);
printf("ํ์ค ํธ์ฐจ: %.5lf", v / 5.0);
return 0;
}
294p_15๋ฒ)
#include<stdio.h>
#include <stdlib.h>
int main()
{
char tile[10] = { '_','_','_','_','_','*','_','_','_','_' };
int STAR = 5;
int way = 0;
srand(time(NULL));
for (int i = 0; i < 10; i++)
{
printf("%c ", tile[i]);
}
printf("\n");
_getch();
for (int k = 0; k < 10; k++)
{
way = rand() % 2;
if (way == 0)
{
if (STAR == 0)
{
continue;
}
tile[STAR] = '_';
tile[--STAR] = '*';
}
else
{
if (STAR == 9)
{
continue;
}
tile[STAR] = '_';
tile[++STAR] = '*';
}
for (int a = 0; a < 10; a++)
{
printf("%c ", tile[a]);
}
printf("\n");
_getch();
}
return 0;
}