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