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

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

by A Lim Han 2023. 1. 10.

# 5์žฅ Lab, Mini Project ๋ฌธ์ œ ํ’€์ด

 

 

196p_Lab)

#include <stdio.h>
#include <math.h>

int main()
{
	int a, b, c;
	double d, x1, x2, x3;

	printf("๊ณ„์ˆ˜ a, b, c๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	scanf_s("%d%d%d", &a, &b, &c);

	d = b * b - 4.0 * a * c;

	if (d == 0)
	{
		x3 = -b / (2 * a);

		printf("ํ•ด๋‹น ์ด์ฐจ ๋ฐฉ์ •์‹์€ ์ค‘๊ทผ %lf์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค.", x3);
	}
	else if (d > 0)
	{
		x1 = ((-b + sqrt(d)) / (2.0 * a));
		x2 = ((-b - sqrt(d)) / (2.0 * a));

		printf("์ฒซ ๋ฒˆ์งธ ์‹ค๊ทผ = %lf\n", x1);
		printf("๋‘ ๋ฒˆ์งธ ์‹ค๊ทผ = %lf\n", x2);
	}
	else
	{
		printf("ํ—ˆ์ˆ˜๊ทผ์ž…๋‹ˆ๋‹ค.\n");
	}

	return 0;
}

 

 

 

 

198p_Mini Project)

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

int main()
{
	int computer, user;

	printf("๊ฐ€์œ„, ๋ฐ”์œ„, ๋ณด ๊ฒŒ์ž„์— ์˜ค์‹  ๊ฒƒ์„ ํ™˜์˜ํ•ฉ๋‹ˆ๋‹ค.\nํ•˜๋‚˜๋ฅผ ์„ ํƒํ•˜์„ธ์š”(๊ฐ€์œ„-0, ๋ฐ”์œ„-1, ๋ณด-2): ");
	scanf_s("%d", &user);

	srand(time(NULL));	//์‹œ๋“œ๊ฐ’์„ ์ฃผ์ง€ ์•Š์œผ๋ฉด ๋‚œ์ˆ˜๊ฐ€ ์ œ๋Œ€๋กœ ์ƒ์„ฑ๋˜์ง€ ์•Š๋Š”๋‹ค.
	computer = rand() % 3;

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

	return 0;
}