RanMagie @ 2023-01-28 19:54:48
一个RE,明明外面能运行……题解全是C++我有点想直接去学又怕基础不够
#include<stdio.h>
int main()
{
int x,y;
char z;
scanf("%d %d %c",&x,&y,&z);
if(z=='+')
printf("%d",x+y);
if(z=='-')
printf("%d",x-y);
if(z=='*')
printf("%d",x*y);
if(z=='/')
printf("%d",x/y);
if(y==0&&z=='/')
printf("Divided by zero!");
if(z!='+'&&z!='-'&&z!='*'&&z!='/')
printf("Invalid operator!");
return 0;
}
by ZQIN_P @ 2023-01-28 19:59:58
@RanMagie 把scanf
读入改成cin
读入
by ppip @ 2023-01-28 20:06:05
@RanMagie divided by zero要放在第一个,且输出后return,否则除以0会出现RE的错误。
可以输入 1 0 /
测试
by ppip @ 2023-01-28 20:09:18
@planet_over_for_ever 帖子已经很明确是C语言了
by ZQIN_P @ 2023-01-28 20:10:10
@ppip 提示我是c,但是为什么看起来和c++那么像
by ppip @ 2023-01-28 20:11:01
@planet_over_for_ever 你说得对
by Dian_ed @ 2023-01-28 20:14:17
@planet_over_for_ever 好像相通的吧?毕竟本来差别就不太大
by RanMagie @ 2023-01-28 20:25:42
@ppip 感谢!过啦
by a2lyaXNhbWUgbWFyaXNh @ 2023-01-28 20:57:40
热知识:gcc编译通过无警告的c语言代码大部分情况下当做c++代码也是可以的
by ppip @ 2023-01-28 21:05:11
@五个下划线 auto()
虽然C没人用auto就是了
玩梗,非杠