What is the output of the C program with Modulo
Division operator with - or Negative numbers.?
int main()
{
int a = -25%-10;
int b = -25%10;
int c = 25%-10;
0
5
printf("a=%d b=%d CF%d", a, b, c);
return 0;
}
Answers
Answer:
a=-5, b=-5 , CF=the value of modulo division will not change only the sign will change and answer will follow the sign of dividend , not follow the sign of divisor
Concept:
The modulus operator is a binary arithmetic operator that works with two operands in the C programming language. It's utilised to figure out the remainder.
Syntax: operand1%operand2;
Given:
#include<stdio.h>
int main()
{
int a = -25%-10;
int b = -25%10;
int c = 25%-10;
printf("a=%d b=%d CF%d", a, b, c);
return 0;
}
Find:
The output of the given C program.
Solution:
The result of a remainder operator has the same sign as the dividend (numerator).
The sign of the left operand determines the outcome for negative integers; if the left operand is positive, the result will be positive; if the left operand is negative, the result will be negative.
∵ In the given code the left operands of a and b are negative so, the result will be negative.
∴ The output will be:
a=-5 b=-5 CF5