Finding the modulo value without using the modulo operator in C

This program helps you to find the modulo value of the dividend without using the modulo operator.

Source code :




#include<stdio.h>

int main(){

int value = 123;  // Dividend
int divisor = 5;  //Divisor

int multiplier = (int)value/divisor; // Finding the multiples of the value
int multiplier_value = multiplier * divisor; //Multiply it with the divisor
int remainder = value - multiplier_value;  //Substract the value with the given value

printf("%d %% %d = %d",value,divisor,remainder);

return 0;

}




Output :

123 % 5 = 3

Output :


                

Comments :