{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# do ... while\n", "\n", "\n", "\n", "# 문제 \n", "다음과 같은 코드가 있다. 코드를 이해하고`do...while`문으로 변환 해보자" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#include \n", "\n", "int main()\n", "{\n", " for (cnt = 0, i = 1, j =2; cnt < n; ++cnt, i += 2, j += 2)\n", " odd += i, even += j;\n", "\n", " return 0;\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 문제\n", "\n", "다음의 코드의 수행 결과를 예측해보자. 무엇을 하는 프로그램인가?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#include \n", "\n", "int main()\n", "{\n", " int row, col;\n", " char char1;\n", " row = col = 0;\n", " \n", " do {\n", " char1 = 'A';\n", " do\n", " {\n", " printf(\"%c\", char1+col);\n", " col++;\n", " } while(col <= row)\n", " row++;\n", " col = 0;\n", " printf(\"\\n\");\n", " } while(row < 5)\n", "\n", " return 0;\n", "}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 문제\n", "\n", "사용자가 입력한 어떤 숫자의 자릿수를 출력하는 프로그램을 `do... while`문을 사용하여 작성하고자 한다. \n", "\n", "힌트: 입력한 숫자를 0이 될 때까지 10으로 계속 나눈 횟수를 카운트 하면됨\n", "\n", "실행 결과의 예:\n", "\n", " Enter a nonnegative integer: 60\n", " The number has 2 digit(s).\n", " \n", " \n", "`while`문을 써서 푼 것과 비교하여 어떤 것이 더 효율적이라고 생각하는가" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "/* Calculates the number of digits in an integer */\n", "\n", "#include \n", "\n", "int main(void)\n", "{\n", " // your code here\n", " return 0;\n", "}" ] } ], "metadata": { "kernelspec": { "display_name": "C", "language": "c", "name": "c" }, "language_info": { "file_extension": ".c", "mimetype": "text/plain", "name": "c" } }, "nbformat": 4, "nbformat_minor": 2 }