Computer Science, asked by Bhawanpreet8377, 1 year ago

If m=5,n=2 what will be the output of m and n execution? (a)n=m+m/n

Answers

Answered by rakeshmohata
7

Answer:

The answer is either 7 or 7.5 for respective conditions

Explanation:

In computer language ,

the execution of any operations takes place using precedence and associativity.

Precedence : When two or more operators are used in any program , the computer chooses the efficient one whose precedence is greater than other.

Here , Operators are = ,+,/

and the precedence here lies as />+> =

so divide Operator(/) will be taken as more efficient, then addition operator(+) and then. equal operator(=).

Note : In C language programs , type casting is done automatically, i.e.

The change of operands as necessary.

If they are declared as integer and some where program it gets a float value , it changes it automatically to integer , only in that part and assign the value and vice versa happens.

So for the required solution for the question,

If m and n are integer

=> n = m + m/n

=> n = 5 + 5/2 = 5 + 2

[ since float 2.5 has a decimal value which integer wont accept and thus only the term before decimal will be accepted]

=> n = 7

If m and n are float

=> n = m + m/n

=> n = 5.00 + 5.00/2.00

=> n = 5.00 + 2.50

=> n = 7.50

----------------------

Similar questions