Arithmetic Expression Evaluation. (Solution in Description Section)

preview_player
Показать описание
IMPORTANT NOTE ON (%) MOD OPERATOR WORKING
As per the C99 standard, the sign obtained as a result of using a MOD(%) operator is the SIGN of the DIVIDEND.
7 (DIVIDEND) % 3 (DIVISOR)

For Example:
7 % 4 = 3
-7 % 4 = -3
7 % -4 = 3
-7 % -4 = - 3

Exercise for Students with Solution in the Description Section
#INCLUDE HEADER FILE

int main()
{
int i ;

i = 10 - -4 + 6 * 2 + 5 ;
printf("%d\n", i);

i = 10 + 5 - 6 % 4 * 2 + 1;
printf("%d\n", i);

i = 10 + -4 + 6 / 5 + 5/3 * 10 % 4 ;
printf("%d\n", i);

i = (10+3*(5 + 6)) + 8 % -5 + 3 / 2 ;
printf("%d\n", i);

i = -4 * 5 % 3 * 2 / 5;
printf("%d\n", i);

return 0;
}

/*
SOLUTIONS FOR VERIFICATION
i = 10 - -4 + 6 * 2 + 5 ; // 31
printf("%d\n", i);

i = 10 + 5 - 6 % 4 * 2 + 1; // 12
printf("%d\n", i);

i = 10 + -4 + 6 / 5 + 5/3 * 10 % 4 ; // 9
printf("%d\n", i);

i = (10+3*(5 + 6)) + 8 % -5 + 3 / 2 ; // 47
printf("%d\n", i);

i = -4 * 5 % 3 * 2 / 5; // 0
printf("%d\n", i);

*/
Рекомендации по теме
Комментарии
Автор

Sir m not able to evaluate expression 4 correctly, plz help

malvikakunwarsen