c语言中,四则运算出错原因

c语言中,四则运算出错原因是什么呢?(实在是没看出来哪里错了-_-||)

img

没啥毛病

#include <iostream>
#include "math.h"
#include <vector>
#include <string>
using namespace std;

int main()
{

   int a,b;
   scanf("%d %d",&a,&b);

   printf("%d + %d = %d\n",a,b,a+b);
   printf("%d - %d = %d\n",a,b,a-b);
   printf("%d * %d = %d\n",a,b,a*b);
   printf("%d / %d = %d",a,b,a/b);


    return 0;
}

img

出什么错?测试无错误。如果要修改的话,可以把除法运算那里修改下。

测试如下:

参考链接:


#include <stdio.h>

int main(void){
    
    int a;
    int b;
    
    scanf("%d %d",&a,&b);
    
    printf("%d + %d = %d\n",a,b,a+b); 
    printf("%d - %d = %d\n",a,b,a-b); 
    printf("%d * %d = %d\n",a,b,a*b); 
//    printf("%d / %d = %d\n",a,b,a/b); 
    // 如果要让除法运算保留一定精度的小数结果
    // 可以修改下除法的打印语句 
    // 以及增加 处理除数为0的情况 
    // https://zhidao.baidu.com/question/462080214960257765.html
    if (b==0){
        printf("除数不能为0.\n");
    } else{
        printf("%d / %d = %f\n",a,b,a*1.0/b);  
    }
    
    return 0;
} 

img

程序本身没问题,可编译出的可执行文件无权限访问执行,建议重启一下电脑就好了