Home > Back-end >  Why t greater than 5 calculation results is not right? Is a question of if statements
Why t greater than 5 calculation results is not right? Is a question of if statements

Time:10-04

# include & lt; stdio.h>
# include & lt; Stdlib. H>

Int main ()
{
Float a, b, s;
Int c, t;
The scanf (" % f, % d ", & amp; S, & amp; T);
If (s
=3)A=10;
Else if (s> 3 & amp; & S<=10)
A=2 * s + 4;
The else
A=3 * s - 6;
If (t<5)
B=0;
The else
B=t % 5 * 2;
C=(int) (a + b);
Printf (" % d ", c);
Return 0;
}

CodePudding user response:

Don't see any problem? What is wrong?

CodePudding user response:

Such as input 12.5 9 will be 34 39 not correct results

CodePudding user response:

Estimate is said that a
B=t % 5 * 2;
The multiplication of higher priority than %, so do the multiplication first
The expression is equivalent to the
B=t % 10

To change the
you have to writeB=(t % 5) * 2;

CodePudding user response:

Fun
reference 3 floor response:
estimation is said that a
B=t % 5 * 2;
The multiplication of higher priority than %, so do the multiplication first
The expression is equivalent to the
B=t % 10

To change the
you have to writeB=(t % 5) * 2;

God wants us to meet a few wrong people wake up a language. Thanks
  • Related