zoukankan      html  css  js  c++  java
  • [刷题] PTA 7-20 简单计算器

    程序:

    #include<stdio.h>
    int main() {
        int a,b;
        char c;
        scanf("%d",&a);
        while(scanf("%c",&c)) {
            switch(c) {
                case('+'):scanf("%d",&b);a+=b;break;
                case('-'):scanf("%d",&b);a-=b;break;
                case('*'):scanf("%d",&b);a*=b;break;
                case('/'):scanf("%d",&b);if(b==0){
                printf("ERROR");return 0; }else a/=b;break;
                case('='):printf("%d",a);return 0;
                default:printf("ERROR");return 0;
            }
        }
        return 0;
    }

    知识点:while,switch-case-default

  • 相关阅读:
    「2019纪中集训Day20」解题报告
    PHP基础入门
    javascript
    正则表达式
    DOM 节点
    对象
    字符串
    函数
    for循环
    jQuery
  • 原文地址:https://www.cnblogs.com/cxc1357/p/10649470.html
Copyright © 2011-2022 走看看