//5
#include <stdio.h>
#include <math.h>
#define SIZE 100
int is_even(int a[], int size, int cu);
int is_odd(int a[], int size,int cu);
int main() {
int a[SIZE];
int count=0;
printf("์ ์๋ฅผ ๋น์นธ์ผ๋ก ๊ตฌ๋ถํด์ ์
๋ ฅํ์ธ์ (๋ง์ง๋ง์ 0)");
for (int i = 0; i < SIZE; i++)
{
scanf_s("%d", &a[i]);
count = i;
if (a[i] == 0)
break;
}
printf("์
๋ ฅ๋ฐ์ ์ ์ ์ค ์ง์๋ %d๊ฐ ํ์๋ %d๊ฐ ",is_even(a,SIZE, count), is_odd(a,SIZE, count));
return 0;
}
int is_even(int a[], int size, int cu) {
int count=0;
for (int i = 0; i < cu; i++)
{
if (a[i] % 2 == 0)
{
count++;
}
}
return count;
}
int is_odd(int a[], int size, int cu) {
int count=0;
for (int i = 0; i < cu; i++)
{
if (a[i] % 2 != 0)
{
count++;
}
}
return count;
}
โ
//1
#include <stdio.h>
int get_perimeter(int width, int hegiht);
int main() {
int w,h,a=0;
printf("๊ฐ๋ก?");
scanf_s("%d",&w);
printf("์ธ๋ก?");
scanf_s("%d",&h);
a = get_perimeter(w, h);
printf("์ง์ฌ๊ฐํ์ ๋๋ : %d",a);
return 0;
}
int get_perimeter(int width, int hegiht) {
int a;
a = width * 2 + hegiht * 2;
return a;
}
//2
#include <stdio.h>
double get_area_of_square(double n);
int main() {
double a;
printf("ํ ๋ณ์ ๊ธธ์ด?");
scanf_s("%lf", &a);
printf("์ ์ฌ๊ฐํ์ ๋ฉด์ : %f",get_area_of_square(a));
return 0;
}
double get_area_of_square(double n) {
return n * n;
}
//3
#include <stdio.h>
#include <math.h>
double distance(int a, int b, int c, int d);
int main() {
int a,b,c,d;
printf("์ง์ ์ ์์์ ์ขํ?");
scanf_s("%d %d",&a, &b);
printf("์ง์ ์ ๋์ ์ขํ?");
scanf_s("%d %d", &c, &d);
printf("(%d,%d) ~ (%d,%d)", a, b, c, d);
printf("์ง์ ์ ๊ธธ์ด: %f",distance(a,b,c,d));
return 0;
}
double distance(int a, int b,int c, int d) {
return sqrt((c - a) * (c - a) + (d - b) * (d - b));
}
//6
#include <stdio.h>
#include <math.h>
#define SIZE 100
int choose_menu(int n);
int main() {
int n=0;
switch (choose_menu(n))
{
case 1:
printf("ํ์ผ ์ด๊ธฐ๋ฅผ ์ํํฉ๋๋ค.");
break;
case 2:
printf("ํ์ผ ์ ์ฅ์ ์ํํฉ๋๋ค.");
break;
case 3:
printf("ํ์ผ ์ธ์๋ฅผ ์ํํฉ๋๋ค.");
break;
case 0:
break;
}
return 0;
}
int choose_menu(int n) {
while (1) {
printf("[1ํ์ผ์ด๊ธฐ 2ํ์ผ์ ์ฅ 3์ธ์ 0์ข
๋ฃ] ์ ํ?");
scanf_s("%d", &n);
if (n == 1) {
return 1;
break;
}
if (n == 2) {
return 2;
break;
}
if (n == 3) {
return 3;
break;
}
if (n == 0) {
return 0;
break; }
}
}
//12
#include <stdio.h>
void is_leap_year();
int main() {
printf("2000~2100 ์ฌ์ด์ ์ค๋
\n");
is_leap_year();
return 0;
}
void is_leap_year() {
int i;
for (i = 2000; i <= 2100; i++) {
if (((i % 4 == 0) && (i % 100 != 0) || (i % 400 == 0)))
printf("%d ", i);
}
}
//13
// 2์๋ฌ 28 ,29 ์์ ํด์ผํจ. ์๋์๊ฐ.
#include <stdio.h>
void get_days_of_month(int n);
int is_leap_year();
int main() {
int n;
printf("์ฐ๋? \n");
scanf_s("%d", &n);
get_days_of_month(n);
return 0;
}
//1์, 3์, 5์, 7์, 8์, 10์, 12์์ 31์ผ๊น์ง ์์..
//4์, 6์, 9์, 11์์ 30์ผ๊น์ง
//2์ ์ค๋
์ ๋ฐ๋ผ..์ค๋
29์ผ ํ๋
์ด๋ฉด 28์ผ..
void get_days_of_month(int n) {
int i;
printf("[%d๋
]\n", n);
for (i = 1; i <= 12; i++) {
printf("%d์:", i);
switch (i)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
printf("31์ผ ");
break;
case 4: case 6: case 9: case 11:
printf("30์ผ ");
break;
case 2:
switch (is_leap_year())
{
case 0:
printf("28์ผ ");
break;
case 1:
printf("29์ผ ");
break;
}
default:
break;
}
}
}
int is_leap_year() {
int i;
for (i = 2000; i <= 2100; i++) {
if (((i % 4 == 0) && (i % 100 != 0) || (i % 400 == 0)))
return 1;
else
return 0;
}
}