Home > other >  C language foundation
C language foundation

Time:09-17

Experimental 2-2-7 integer arithmetic (10)

Subject to code program, calculate and two positive integers, difference, product, business and output, subject to ensure all input and output in the range of the integer
Input format:

Input in A row in the given two positive integers A and B,
The output format:

In four lines in accordance with the format "operator B=results" sequence output and, difference, product, company,
Input the sample:

3 2

Output sample: time limit: 400 ms
Memory limit: 64 MB
Code length restrictions: 16 KB

3 + 2=5
3-2=1
3 * 2=6
L=1
My answer: # include
Int main ()
{
Int A, B, the result;
The scanf (" % d % d ", & amp; A, & amp; B);
Result=A + B;
Printf (" % d % d=% d \ n ", A, B, result);
Result=A - B;
Printf (" % d, % d=% d \ n ", A, B, result);
Result=A * B;
Printf (" % d % d *=% d \ n ", A, B, result);
Result=A/B;
Printf (" % d/d=% d \ % n ", A, B, result);


return 0;
}
Standard answer:
#include

Int main ()
{
Int a, b;
The scanf (" % d % d ", & amp; A, & amp; B);
Printf (" % d % d=% d \ n ", a, b, a + b);
Printf (" % d, % d=% d \ n ", a, b, a - b).
Printf (" % d % d *=% d \ n ", a, b, a * b);
Printf (" % d/d=% d \ % n ", a, b, a/b);
return 0;
}
Would you please tell me why my answer is wrong, the following is the reason for the error
A.c: In the function 'main' :
A.c: 5:3: warning: ignoring the return value of the scanf, declared with the attribute warn_unused_result [- Wunused - the result]
The scanf (" % d % d ", & amp; A, & amp; B);
^ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
0 are the same as the sample, change the number format error 1 ms 256 KB
1 subtraction is negative, division results of 0 format error 2 ms 256 KB

CodePudding user response:

According to the experience of my wrong topic, you may be the last in the printf Spaces between Numbers and symbols did not cause

CodePudding user response:

Printf (" % d % d=% d \ n ", A, B, A + B);
Printf (" % d, % d=% d \ n ", A, B, A - B).
Printf (" % d % d *=% d \ n ", A, B, A * B);
Printf (" % d/d=% d \ % n ", A, B, A/B);

CodePudding user response:

Warning: ignoring the return value of the scanf, declared with the attribute warn_unused_result [- Wunused - the result]
The scanf (" % d % d ", & amp; A, & amp; B);

Input the parameters of the need to decide whether an integer, if there is no judgment will be submitted to the the wrong
Add
If (the scanf (" % d % d ", & amp; A, & amp; B)!=1) {
Printf (" not int type ");
}
  • Related