본문 바로가기
728x90

c codes3

[C Examples] struct을 활용한 영화 정보 출력하기 struct을 활용한 영화 정보 출력하기 포스트 난이도: HOO_Intern # Example codes 이번 포스트에서는 C에서 struct을 어떻게 사용할 수 있는지를 살펴볼 수 있다. 아래의 예제코드는 간략한 영화 데이터를 struct을 활용해서 저장하고 출력해내고 있다. 영화 정부에 들어가 데이터의 경우 동일한 type들을 가지고 있기 때문에 struct을 통해서 타입을 설정해 준 다음 MovieData라는 struct에 저장되어 있는 방식을 movie1과 movie2에서 사용하고 있다. 여기서 struct은 어렵게 생각할 필요없이 마치 글을 작성하는 데 있어서 정해진 양식을 저장해 준 다음에 불러서 반복적으로 사용하는 거와 비슷하다고 생각하면 된다. 그래서 우리는 한국말로 struct을 "구조체.. 2023. 10. 2.
[C Examples] 24시간을 12시간 표기로 바꾸기 예제코드: if(), else 24시간을 12시간 표기로 바꾸기 예제코드: if(), else 포스트 난이도: HOO_Intern # Example Codes #include #include int main() { int userHour, userMinute, hour; printf("Time(e.g., 23:15):"); scanf("%d:%d", &userHour, &userMinute); if (userHour > 11) { hour = userHour - 12; if(hour == 12){ printf("Time is 00:%d AM\n", userMinute); } else{ printf("Time is %d:%d PM\n", hour, userMinute); } } else{ printf("Time is %d:%d AM\n.. 2023. 2. 18.
[C Examples] GPA 계산기 예제코드: if(), else if() GPA 계산기 예제코드: if(), else if() 포스트 난이도: HOO_Intern # Example Codes #include #include int main() { float gpa; printf("Enter the GPA:\n"); scanf("%f.2", &gpa); if (gpa > 3.9 || gpa == 3.9){ printf("Dean's list.\n"); } else if(gpa < 2.00){ printf("GPA is below the graduation requirement.\n"); } printf("Coded by HOO.\n"); return 0; } Enter the GPA: 3.9 Dean's list. Coded by HOO. Enter the GPA: 1.96 G.. 2023. 2. 17.
728x90