Chinaunix首页 | 论坛 | 博客

分类: 信息化

2014-12-29 10:57:27


点击(此处)折叠或打开

  1. #include <stdio.h>


  2. double calculetor(double a,double b, char myoperator)
  3. {
  4.     if(myoperator=='+')
  5.     {
  6.         return a+b;
  7.     }
  8.     else if(myoperator=='-')
  9.     {
  10.         return a-b;
  11.     }
  12.     else if(myoperator=='*')
  13.     {
  14.         return a*b;
  15.     }
  16.     else if(myoperator=='/')
  17.     {
  18.         if(b=0)
  19.         {
  20.             printf("除数不能为零 \n");
  21.         }
  22.         else
  23.         {
  24.             return a/b;
  25.         }
  26.     }
  27.     else
  28.     {
  29.         printf("亲,这个问题太难了,我也不会算\n");
  30.     }
  31. }
  32.     int main()
  33.     {
  34.         double a,b;
  35.         char myoperator;
  36.         scanf("%lf %c %lf",&a,&myoperator ,&b);
  37.         printf("%lf\n",calculetor(a,b,myoperator));
  38.         return 0;
  39.     }

阅读(1284) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~