0

#include <stdio.h> int main() { int x=7%4*3/2; printf("%d \n",x); return 0;}

Can anyone tell me why it's ans is 1 unless in coding it gives ans 4.

12th Sep 2023, 8:00 AM
ANKIT RAJ
ANKIT RAJ - avatar
1 Odpowiedź
+ 4
ANKIT RAJ In this program the expression `7%4*3/2` is evaluated according to the operator precedence rules. #This operator `%` has higher precedence #than the multiplication operator `*` # and then division operator `/`. So given expression is: `(7%4)*3/2` First, `7%4` which gives the remainder of 7 divided by 4, which is 3. Note that:- The `%` operator is called the modulus operator. It calculates the remainder when one number is divided by another. hence,7%4=3 Second, `(7%4)*3`=(3)*3 which is 3 multiplied by 3, resulting in 9. Finally, `9/2` which gives the integer division of 9 by 2, resulting in 4. Note that:- The `/` operator is used for division. It performs division between two numbers and returns the quotient.. hence, the answer is 4, not 1.
12th Sep 2023, 8:14 AM
Darpan kesharwani🇮🇳[Inactive📚]
Darpan kesharwani🇮🇳[Inactive📚] - avatar