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

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

by A Lim Han 2023. 1. 27.

# 11์žฅ Programming ํ’€์ด

 

 

455p_1๋ฒˆ)

#include <stdio.h>

int main()
{
	int i = 0;
	char yes_or_no;

	union student
	{
		char number[50];
		char student_number[50];
		char name[50];
		char phone[50];
	};

	union student user[100];

	printf("ํ•™์ƒ์ด์‹ญ๋‹ˆ๊นŒ?: ");
	scanf_s("%c", &yes_or_no);

	if (yes_or_no == 'y')    //ํ•™์ƒ์ผ ๊ฒฝ์šฐ
	{
		printf("์„ฑํ•จ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
		rewind(stdin);
		gets_s(user[i].name, 50);

		printf("ํ•™๋ฒˆ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
		rewind(stdin);
		gets_s(user[i].student_number, 50);

		printf("์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
		rewind(stdin);
		gets_s(user[i].phone, 50);
	}
	else    //ํ•™์ƒ ์‹ ๋ถ„์ด ์•„๋‹ ๊ฒฝ์šฐ
	{
		printf("์„ฑํ•จ์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
		rewind(stdin);
		gets_s(user[i].name, 50);

		printf("์ฃผ๋ฏผ๋“ฑ๋ก ๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
		rewind(stdin);
		gets_s(user[i].number, 50);

		printf("์ „ํ™”๋ฒˆํ˜ธ๋ฅผ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
		rewind(stdin);
		gets_s(user[i].phone, 50);
	}

	return 0;
}

 

 

 

 

455p_2๋ฒˆ)

#include <stdio.h>

int main()
{
	struct email
	{
		char sender[20];
		char receiver[20];
		char text[50];
		char title[20];
		char date[20];
	};

	struct email user =
	{
		"AA", "BB", "Let's meet at 7 pm on monday.", "Time to meet", "2021.02.04"
	};

	printf(" from. %s\n", user.sender);
	printf("-ใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…ก-------------\n");
	printf("| Title: %s                            |\n", user.title);
	printf("|                                                |\n");
	printf("| %s                  |\n", user.text);
	printf("|                                                |\n");
	printf("|                                      %s|\n", user.date);
	printf("-ใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…กใ…ก-------------\n");
	printf("                                       To. %s\n", user.receiver);

	return 0;
}

 

 

 

 

455p_3๋ฒˆ)

#include <stdio.h>

struct add 
{
    float x;
    float y;
};

void calculate(struct add a, struct add b)
{
    printf("%.1f + %.1fi\n", a.x + b.x, a.y + b.y);
}

int main() 
{
    struct add a;
    struct add b;

    printf("์ฒซ ๋ฒˆ์งธ ๋ณต์†Œ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค(a,b):");
    scanf_s("%f %f", &a.x, &a.y);

    printf("๋‘ ๋ฒˆ์งธ ๋ณต์†Œ์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค(a,b):");
    scanf_s("%f %f", &b.x, &b.y);

    calculate(a, b);

    return 0;
}

 

 

 

 

455p_4๋ฒˆ)

#include <stdio.h>

struct time
{
	int hour;
	int min;
	int sec;
};

struct time start;
struct time end;

void diff_time(struct time start, struct time end)
{
	printf("์†Œ์š” ์‹œ๊ฐ„: %d์‹œ๊ฐ„ %d๋ถ„ %d์ดˆ\n", end.hour - start.hour, end.min - start.min, end.sec - start.sec);
}

int main()
{
	printf("์‹œ์ž‘ ์‹œ๊ฐ„: ");
	scanf_s("%d %d %d", &start.hour, &start.min, &start.sec);

	printf("์ข…๋ฃŒ ์‹œ๊ฐ„: ");
	scanf_s("%d %d %d", &end.hour, &end.min, &end.sec);

	diff_time(start, end);

	return 0;
}

 

 

 

 

456p_5๋ฒˆ)

#include <stdio.h>

struct employee
{
	int number;
	char name[10];
	char phone[20];
	int age;
};

int main()
{
	struct employee array[10] =
	{
		{ 1, "AA", "010-1111-1111", 20},
		{ 2, "BB", "010-2222-2222", 22},
		{ 3, "CC", "010-3333-3333", 33},
		{ 4, "DD", "010-4444-4444", 44},
		{ 5, "EE", "010-5555-5555", 45},
		{ 6, "FF", "010-6666-6666", 30},
		{ 7, "GG", "010-7777-7777", 77},
		{ 8, "HH", "010-8888-8888", 37},
		{ 9, "II", "010-9999-9999", 40},
		{ 10, "JJ", "010-0000-0000", 41},
	};

	for (int i = 0; i < 10; i++)
	{
		if (array[i].age >= 20 && array[i].age <= 30)
		{
			printf("%d, %s, %s, %d\n", array[i].number, array[i].name, array[i].phone, array[i].age);
		}
	}

	return 0;
}

 

 

 

 

456p_6๋ฒˆ)

#include <stdio.h>
#include <string.h>

struct system
{
	char name[10];
	int price;
	int num;
	int total;
};

int main()
{
	struct system A[100] =
	{
		{ "Apple", 1000, 3, 3000 },
		{ "Banana", 1200, 2, 2400 },
		{ "Plum", 2000, 5, 10000 }
	};

	char input[10];

	printf("๊ฒ€์ƒ‰ํ•˜์‹ค ์ƒํ’ˆ๋ช…์„ ์ž…๋ ฅํ•ด ์ฃผ์„ธ์š”: ");
	gets_s(input, 10);
	
	for (int i = 0; i < 3; i++)
	{
		if (strcmp(input, A[i].name) == 0)
		{
			printf("=========================\n");
			printf("์ƒํ’ˆ๋ช…: %s\n", A[i].name);
			printf("์ƒํ’ˆ ๊ฐ€๊ฒฉ: %d\n", A[i].price);
			printf("์ƒํ’ˆ ๊ฐœ์ˆ˜: %d\n", A[i].num);
			printf("=========================\n");
		}
	}

	return 0;
}

 

 

 

 

456p_7๋ฒˆ)

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

enum game 
{ 
    scissors, rock, paper 
};

int main() 
{
    int user = 10;

    enum game com;

    srand(time(NULL));
    com = rand() % 3;

    printf("๊ฐ€์œ„(0), ๋ฐ”์œ„(1), ๋ณด(2)๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”: ");
    scanf_s("%d", &user);

    if (com == user) 
    {
        printf("๋น„๊ฒผ์Šต๋‹ˆ๋‹ค.");
    }
    else if (user == rock) 
    {
        if (com == paper)
        {
            printf("์ปดํ“จํ„ฐ: %d, ์‚ฌ์šฉ์ž: %d\n", com, user);
            printf("์ปดํ“จํ„ฐ ์Šน๋ฆฌ\n");
        }
        else
        {
            printf("์ปดํ“จํ„ฐ: %d, ์‚ฌ์šฉ์ž: %d\n", com, user);
            printf("์‚ฌ์šฉ์ž ์Šน๋ฆฌ\n");
        }
    }
    else if (user == paper) 
    {
        if (com == scissors)
        {
            printf("์ปดํ“จํ„ฐ: %d, ์‚ฌ์šฉ์ž: %d\n", com, user);
            printf("์ปดํ“จํ„ฐ ์Šน๋ฆฌ\n");
        }
        else
        {
            printf("์ปดํ“จํ„ฐ: %d, ์‚ฌ์šฉ์ž: %d\n", com, user);
            printf("์‚ฌ์šฉ์ž ์Šน๋ฆฌ\n");
        }
    }
    else
    {
        if (com == rock)
        {
            printf("์ปดํ“จํ„ฐ: %d, ์‚ฌ์šฉ์ž: %d\n", com, user);
            printf("์ปดํ“จํ„ฐ ์Šน๋ฆฌ\n");
        }
        else
        {
            printf("์ปดํ“จํ„ฐ: %d, ์‚ฌ์šฉ์ž: %d\n", com, user);
            printf("์‚ฌ์šฉ์ž ์Šน๋ฆฌ\n");
        }
    }

    return 0;
}