C言語は簡単な計算機(プラス、マイナス、乗数、除算、型取り)を作る

1245 ワード

C言語は簡単な計算機(プラス、マイナス、乗数、除算、型取り)を作る
#include

int main()
{
    double number1=0.0;
    double number2=0.0;
    char operation=0;

    a:
    printf("         (  a+b):
"); scanf("%lf%c%lf",&number1,&operation,&number2); if(operation=='+') { printf(" , :%lf
",number1+number2); } else if(operation=='-') { printf(" , :%lf
",number1-number2); } else if(operation=='*') { printf(" , :%lf
",number1*number2); } else if(operation=='/') { if(number2==0) { printf(" :
"); goto a; } else { printf(" , :%lf
",number1/number2); } } else if(operation=='%') { if(number2==0) { printf(" :
"); goto a; } else { printf(" , :%ld
",(long)number1%(long)number2); } } else { printf(" , !"); } return 0; }