L1-037 A除以B (10分)
真的是简单题哈 ———— 给定两个绝对值不超过 (100) 的整数 (A) 和 (B),要求你按照 A/B=商
的格式输出结果。
输入格式:
输入在第一行给出两个整数 (A) 和 (B) ((−100 leq A,B leq 100)),数字间以空格分隔。
输出格式:
在一行中输出结果:如果分母是正数,则输出 A/B=商
;如果分母是负数,则要用括号把分母括起来输出;如果分母为零,则输出的商应为 Error
。输出的商应保留小数点后 (2) 位。
输入样例1:
-1 2
输出样例1:
-1/2=-0.50
输入样例2:
1 -3
输出样例2:
1/(-3)=-0.33
输入样例3:
5 0
输出样例3:
5/0=Error
代码:
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
cin>>a>>b;
cout<<a<<'/';
if(b<0)cout<<'('<<b<<")=";
else cout<<b<<'=';
if(b)cout<<fixed<<setprecision(2)<<a*1.0/b<<endl;
else cout<<"Error"<<endl;
return 0;
}