[C Examples] 누가 시험을 잘봤을까#2 (exam highest, lowest, average): for loop, array, if statement, void)
누가 시험을 잘 봤을까#2 (exam highest, lowest, average): for loop, array, if statement, void) 포스트 난이도: HOO_Junior # Example codes 이번 예제코드는 "누가 시험을 잘 봤을까" 포스트에 이은 두 번째 버전의 예제코드이다. for loop, array, if statement를 사용하고 있는 건 기존 포스트에 나와있는 코드와 동일하지만 void를 사용해서 코드 구조 자체를 바꾸어 보았다. 이처럼 반복적으로 사용하는 기능에 대해서는 void를 사용해서 main과 구분하여 사용이 가능하다. 처음 c 프로그래밍을 배우는 학생들에게 있어서 main에 모든 걸 다 쏟아 부는 게 훨씬 쉽고 간단하게 느껴진다는 걸 글쓴이도 백 퍼센트 이..
2023. 9. 19.
[C Examples] 누가 시험을 잘봤을까 (exam highest, lowest, average): for loop, array, if statement
누가 시험을 잘 봤을까 (exam highest, lowest, average): for loop, array, if statement 포스트 난이도: HOO_Intern # Example Codes 이번 포스트는 C언어를 기반으로 한 최댓값과 최솟값 그리고 평균값을 구해보는 예제코드이다. 예제코드에서 중점적으로 살펴봐야 할 부분은 배열을 어떻게 활용하고 있는지이다. 아래의 예제코드는 1차 배열을 활용하여 각 값들을 비교하여 원하는 값을 산출해내고 있다. #include int main() { int exam[] = { 70, 80, 94, 85, 47, 68, 98, 77, 85, 88 }; int highest = exam[0]; int lowest = exam[0]; float total = 0; ..
2023. 9. 19.
[C Examples] C 예제코드: 사칙연산 계산기 만들기, switch()
C 예제코드: 사칙연산 계산기 만들기, switch() 포스트 난이도: HOO_Junior # Example Codes #include #include int main() { int num1,num2; float result; char ch; printf("Enter first number: "); scanf("%d",&num1); printf("Enter second number: "); scanf("%d",&num2); printf("Choose operation to perform (+,-,*,/,%): "); scanf(" %c", &ch); printf("You typed %c operator. \n", ch); switch(ch) { case '+': result=num1+num2; break..
2023. 4. 14.
[C Examples] 7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d
7 Digit ISSN, 8번째 숫자 산출하기 예제코드: if(), else(), %d 포스트 난이도: HOO_Junior # Example Codes #include int main() { int frontISSN, frontISSNOne, frontISSNTwo, frontISSNThree, frontISSNFour, backISSN, backISSNOne, backISSNTwo, backISSNThree, backISSNPer, modNum, unknownNum; printf("Enter the 7 digit ISSN in form of XXXX-XXX:"); scanf("%d - %d", &frontISSN, &backISSN); frontISSNOne = frontISSN/1000; frontI..
2023. 2. 15.
[C Examples] 총 지불액 계산기(팁, 세금 포함): float, scanf, %.f
총 지불액 계산기(팁, 세금 포함): float, scanf, %.f 포스트 난이도: HOO_Intern # Example codes #include #include int main() { int numPeople; float bill, tips, tax, billAfter, amountPerson, tipPerson; printf("총 액수를 입력하세요.\n"); scanf("%f",&bill); printf("총 사람 수를 입력하세요.\n"); scanf("%d",&numPeople); printf("Tip percentage를 입력하세요.\n"); scanf("%f",&tips); tax = bill*0.05; printf("Tax: %.2f $\n", tax); billAfter=bill+tax;..
2023. 1. 30.