MapleStory Finger Point

๐Ÿ”ต C,C++,C#/๐Ÿ“šCore C_Programming

[C/Core C Programming] Chapter6

HYEJU01 2023. 3. 27. 19:19
//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;
		
	}
}