% is called as Modulus Operator.
It is a binary Operator.
It gives the remainder of the supplied operands.
The modulus operator requires that both operands be integers & the second operand be nonzero.
Example
main()
{
int x;
x=5%2;
printf("d",x);
}
If numerator is less than denominator we get numerator as remainder.
main()
{
int x;
x=7%70;
printf("%d",x);
}
The sign of the result depends only on the sign of numerator but not on denominator.
main()
{
printf("%d\n",4%3); //gives 1
printf("%d\n",4%-3);//gives 1
printf("%d\n",-4%3);//gives -1
printf("%d\n",-4%-3);//gives -1
}
Modulus operator on float values is not applicable.
It is a binary Operator.
It gives the remainder of the supplied operands.
The modulus operator requires that both operands be integers & the second operand be nonzero.
Example
main()
{
int x;
x=5%2;
printf("d",x);
}
If numerator is less than denominator we get numerator as remainder.
main()
{
int x;
x=7%70;
printf("%d",x);
}
The sign of the result depends only on the sign of numerator but not on denominator.
main()
{
printf("%d\n",4%3); //gives 1
printf("%d\n",4%-3);//gives 1
printf("%d\n",-4%3);//gives -1
printf("%d\n",-4%-3);//gives -1
}
Modulus operator on float values is not applicable.
No comments:
Post a Comment