7-5 A divided by B (10 minutes)

Ha is really simple question - given absolute value is not more than two integers A and B 100, requiring you follow the "A / B = List" output format results.

Input format:
Input Given two integers A and B (-100≤A, B≤100) in the first row, separated by spaces between numbers.

Output format:
the output in the line: If the denominator is positive, the output "A / B = List"; if the denominator is negative, the denominator enclosed in braces output; If the denominator is zero, then the output should be commercially Error. Business output should retain two decimal places.

Input Sample 1:
-12
Output Sample 1:
-1 / 2 = -0.50
Input Sample 2:
1-3
Output Sample 2:
1 / (- 3) = - 0.33
Input Sample 3:
50
output sample. 3:
. 5/0 = Error

 

 1 int main()
 2 {
 3     int a,b;
 4     float c=0.0;
 5     scanf("%d %d",&a,&b);
 6     c=(float)a/b;
 7     if(b<0)
 8     printf("%d/(%d)=%.2f",a,b,c);
 9     else if(b==0)
10     printf("%d/%d=Error",a,b);
11     else
12     printf("%d/%d=%.2f",a,b,c);
13     return 0;
14 } 

Guess you like

Origin www.cnblogs.com/xiaolitongxueyaoshangjin/p/12106566.html