1 条题解
-
0
C++ :
#include<bits/stdc++.h> using namespace std; int main(){ double a,b; char c; cin>>a>>b>>c; if(c=='*'){ printf("%.1lf",a*b); } else if(c=='/'&&b!=0){ printf("%.1lf",a/b); } else if(c=='+'){ printf("%.1lf",a+b); } else if(c=='-'){ printf("%.1lf",a-b); }else if(c!='-'&&c!='+'&&c!='*'&&c!='/')cout<<"运算符有误"; else if(c=='/'&&b==0) cout<<"除数不能为零"; }
Python :
# coding=utf-8 x=float(input()) y=float(input()) op=input() if op=="+": z=x+y print(format(z,'.1f')) elif op=="-": z=x-y print(format(z,'.1f')) elif op=="*": z=x*y print(format(z,'.1f')) elif op=="/": if y!=0: z=x/y print(format(z,'.1f')) else: print("除数不能为零") else: print("运算符有误")
- 1
信息
- ID
- 534
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- (无)
- 递交数
- 0
- 已通过
- 0
- 上传者