[c언어] 문자를 case로 구분하는 swich case 문

|



문자를 case로 구분하는 swich case 문에 대해 알아보는 프로그램
연산기호(+,-,*,/,%)를 입력하면 해당된 연산의 결과를 출력하는 프로그램을 작성

#include <stdio.h>
void main()
{
    char operand;
    int a=8, b=5;
    printf("연산자(+-*/%%)를 입력하고 Enter\n");
    printf("연산자 : ");
    scanf("%c", &operand);
    switch(operand)
    {
    case '+' :
        printf("a+b=%d", a+b);
        break;
    case '-' :
        printf("a-b=%d", a-b);
        break;
    case '/' :
        printf("a/b=%d", a/b);
        break;
    case '*' :
        printf("a*b=%d", a*b);
        break;
    case '%' :
        printf("a%b=%d", a%b);
        break;
    default :
        printf("계산할 수 없습니다.");
    }
}       

# 실행 결과

  ::