c语言计算器

1820阅读 0评论2014-12-15 孙超越
分类:C/C++


点击(此处)折叠或打开

  1. #include<stdio.h>

  2. double calcutotor(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.             return 0;
  22.         }
  23.         else
  24.         {
  25.             return a/b;
  26.         }
  27.     }
  28.     else
  29.     {
  30.         printf("亲,不能这样操作\n");
  31.         return 0;
  32.     
  33.     }
  34. }
  35. int main()
  36. {
  37.     double a,b;
  38.     char myoperator;
  39.     scanf("%lf%c%lf",&a,&myoperator,&b);
  40.     printf("%lf\n" ,calcutotor(a,b,myoperator));
  41.     return 0;

  42. }

上一篇:定义一个整形的数组a[10]从键盘输入10
下一篇:数组练习