L1-037. A divided by B

 Really simple question - given two integers A and B whose absolute value does not exceed 100, you are asked to output the result in the format "A/B=quotient".

Input format:

The input gives two integers A and B (-100 <= A, B, <= 100) on the first line, separated by spaces.

Output format:

Output the result in one line: if the denominator is positive, output "A/B=quotient"; if the denominator is negative, wrap the denominator in parentheses and output; if the denominator is zero, the output quotient should be "Error" . The output quotient should have 2 decimal places.

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

Code:

#include<stdio.h>
intmain()
{
    int i,j,n,m,k,t;
    scanf("%d %d",&n,&m);
    if(m==0)
    {
       printf("%d/0=Error",n);
    }
    else if(m>0)
    {
        printf("%d/%d=%.2lf",n,m,1.0*n/m);
    }
    else
    {
        printf("%d/(%d)=%.2lf",n,m,1.0*n/m);
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325517443&siteId=291194637