回覆列表
  • 1 # lanfengz3

    #include

    #include

    int main(void)

    {

    float data1,data2;

    char op;

    char reply;

    do{

    printf("Please enter the expression:\n");

    scanf("%f %c%f",&data1,&op,&data2);//%c前有一空格

    switch(op)

    {

    case "+":printf("%f+%f=%f\n",data1,data2,data1+data2);break;

    case "-":printf("%f-%f=%f\n",data1,data2,data1-data2);break;

    case "*":printf("%f*%f=%f\n",data1,data2,data1*data2);break;

    case "/":if(fabs(data2)

    {

    printf("Division by zero!\n");

    }

    else

    {

    printf("%f/%f=%f\n",data1,data2,data1/data2);

    }

    break;

    default:printf("Unknown operator!\n");

    }

    printf("Do you want to continue(Y/N or y/n?)");

    scanf(" %c",&reply);//%c前有一空格

    }

    while(reply=="Y"||reply=="y");

    printf("Program is over!\n");

    return 0;

    }

    注意一定要有空格,否則程式無法正常執行

  • 中秋節和大豐收的關聯?
  • 用了三個月的iPhone xr128G的換一個8p 256G的值得嗎?