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

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

by A Lim Han 2023. 1. 18.

# 8์žฅ Programming ํ’€์ด (1)

 

 

336p_1๋ฒˆ)

#include <stdio.h>

void cal(double a, double b)
{
	printf("x = ");
	scanf_s("%lf", &a);

	printf("y = ");
	scanf_s("%lf", &b);

	printf("f(x,y) = %.3lf\n\n", (1.5 * a) + (3.0 * b));
}

int main()
{
	while (1)
	{
		double x = 0;
		double y = 0;

		cal(x, y);
	}

	return 0;
}

 

 

 

 

336p_2๋ฒˆ)

#include <stdio.h>

double get_bigger(double a, double b)
{
	printf("์‹ค์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	scanf_s("%lf", &a);

	printf("์‹ค์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	scanf_s("%lf", &b);

	if (a > b)
	{
		return a;
	}
	else
	{
		return b;
	}
}

int main()
{
	int x = 0;
	int y = 0;

	printf("๋” ํฐ ์ˆ˜๋Š” %.3lf์ž…๋‹ˆ๋‹ค.", get_bigger(x, y));

	return 0;
}

 

 

 

 

336p_3๋ฒˆ)

#include <stdio.h>

void star(void)
{
	printf("***************************\n");
}

int main()
{
	star();
	printf("Hello World\n");
	star();

	return 0;
}

 

 

 

 

336p_4๋ฒˆ)

#include <stdio.h>

int get[] = { 0 };

int div(int a)
{
	int r = 0;

	for (int i = 1; i <= a; i++)
	{
		if (a % i == 0)
		{
			get[r] = i;
			r++;
		}
	}

	return r;
}

int main()
{
	int p = 0;

	printf("์ •์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค: ");
	scanf_s("%d", &p);

	printf("%d์˜ ์•ฝ์ˆ˜: ", p);

	for (int i = 0; i < div(p); i++)
	{
		printf("%d ", get[i]);
	}

	return 0;
}

 

 

 

 

337p_5๋ฒˆ)

#include <stdio.h>

void prime() 
{
    int p = 0;
    int k = 0;

    for (p = 2; p < 100; p++) 
    {
        for (k = 2; k < p; k++) 
        {
            if (p % k == 0)
            {
                break;
            }
        }

        if (p == k) 
        {
            printf("%d ", p);
        }
    }
}

void main() 
{
    prime();
    
    return 0;
}

 

 

 

 

337p_6๋ฒˆ)

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

void power()
{
	for (int i = 0; i <= 10; i++)
	{
		printf("%d ", (int)pow(3, i));
	}
}

int main()
{
	power();

	return 0;
}

 

 

 

 

337p_7๋ฒˆ)

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

double dist()
{
	int x1, y1, x2, y2;

	printf("์ฒซ ๋ฒˆ์งธ ์ ์˜ ์ขŒํ‘œ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค(x, y): ");
	scanf_s("%d %d", &x1, &y1);

	printf("๋‘ ๋ฒˆ์งธ ์ ์˜ ์ขŒํ‘œ๋ฅผ ์ž…๋ ฅํ•˜์‹œ์˜ค(x, y): ");
	scanf_s("%d %d", &x2, &y2);

	double result = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));

	return result;
}

int main()
{
	printf("๋‘ ์  ์‚ฌ์ด์˜ ๊ฑฐ๋ฆฌ๋Š” %.3lf ์ž…๋‹ˆ๋‹ค.\n", dist());

	return 0;
}