๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ C Programming/๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ_๊ฐœ์ • 3ํŒ

[๋ˆ„๊ตฌ๋‚˜ ์‰ฝ๊ฒŒ ์ฆ๊ธฐ๋Š” C ์–ธ์–ด ์ฝ˜์„œํŠธ - ๊ฐœ์ • 3ํŒ] 7์žฅ Programming ํ’€์ด (2)

by A Lim Han 2023. 1. 15.

# 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", &reg);

            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;
}