Warning: Declaration of action_plugin_changes::register($controller) should be compatible with DokuWiki_Action_Plugin::register(Doku_Event_Handler $controller) in /volume1/web/dokuwiki/lib/plugins/changes/action.php on line 0 Warning: Declaration of syntax_plugin_code::handle($aMatch, $aState, $aPos, &$aHandler) should be compatible with DokuWiki_Syntax_Plugin::handle($match, $state, $pos, Doku_Handler $handler) in /volume1/web/dokuwiki/lib/plugins/code/syntax.php on line 42 Warning: Declaration of syntax_plugin_code::render($aFormat, &$aRenderer, &$aData) should be compatible with DokuWiki_Syntax_Plugin::render($format, Doku_Renderer $renderer, $data) in /volume1/web/dokuwiki/lib/plugins/code/syntax.php on line 42 c_quizz6 [Protocol Engineering Lab.]

User Tools

Site Tools


c_quizz6
/* filename: p1.c */
/* 사칙연산 계산 프로그램 */
 
/* 숙제 요구사항 */
/* 숫자가 아닌 다른 값이 입력으로 들어 올때, 숫자를 입력 받도록 변경 */
/* 프로그램을 종료하지 않고, 사용자로 부터 숫자를 입력 받도록 해야 함 */
 
#include <stdio.h>
 
float add(float x, float y);
float sub(float x, float y);
float mul(float x, float y);
float div(float x, float y);
 
int main(void) {
        float result;
        float x, y;
        char op;
 
        printf("사칙연산 프로그램\n");
        printf("입력의예) 10 * 3\n");
        scanf("%f %c %f", &x, &op, &y);
 
        switch(op) {
                case '+':
                result = add(x, y);
                break;
 
                case '-':
                result = sub(x, y);
                break;
 
                case '*':
                result = mul(x, y);
                break;
 
                case '/':
                result = div(x, y);
                break;
 
                default:
                printf("사칙연산자(+, -, *, /)를 제대로 입력하세요\n");
                return(0);
        }
 
        printf("= %f\n", result);
 
        return(0);
}
 
float add(float x, float y) {
        return (x + y);
}
 
float sub(float x, float y) {
        return (x - y);
}
 
float mul(float x, float y) {
        return (x * y);
}
 
float div(float x, float y) {
        return (x / y);
}
c_quizz6.txt · Last modified: 2015/05/04 01:48 by jonghyouk