• 四则小运算


    #include <stdio.h>
    #include <stdlib.h>
    #include <ctype.h>
    #include <string>
    bool CheckSymbol(char s)
    {
        char ch[4]={'+','-','*','/'};
        for (int i=0;i<4;i++)
        {
            if(s==ch[i]) return true;
        }
      return false;
    }
     
    bool CheckValid(const char p[10])
    {
       
      int start=-1,i=0;
      while (p[i])
       {
          if(isdigit(p[i])||p[i]=='.')
          {
            if(start==-1)
            {
               start=i;
            }
          }
          else
          {
             return false;
          }
          i++;
       }
             
      return true;
    }
    void main(void)
    {
        char b[10],ch;
        float a,c,digits[1];
        scanf("%f%c%s",&a,&ch,b);
        if(CheckValid(b))
        {
            if (CheckSymbol(ch))
            {
                digits[0]=atoi(b);
                if (ch=='+')
                    c=a+digits[0];
                if (ch=='-')
                    c=a-digits[0];
                if (ch=='*')
                    c=a*digits[0];
                if (ch=='/')
                {
                    if(digits[0]==0)printf("除数不能为零 ");
                    else c=a/digits[0];
                    return;
                }
                 
                printf("%5.2f%c%5.2f",a,ch,digits[0]),
                    printf("="),
                    printf("%5.2f ",c);
            }
            else printf("四则运算符号有误 ");
        }
        else printf("error,右操作含有非法字符 ");
     
     }

  • 相关阅读:
    spring MVC 整合mongodb
    Spring Data MongoDB example with Spring MVC 3.2
    SpringMVC整合Mongodb开发 架构搭建
    spring MVC、mybatis配置读写分离
    淘宝网架构分享总结[转]
    淘宝分布式数据层:TDDL[转]
    基于XMPP实现的Openfire的配置安装+Android客户端的实现[转]
    基于开源 Openfire 聊天服务器
    bootstrapUI
    京东手机webapp商城
  • 原文地址:https://www.cnblogs.com/xhl1234/p/5269672.html
Copyright © 2020-2023  润新知