C Program to find remainder without using the modulus operator


In this program, You will learn how to find the remainder without using a modulus operator in c.


0 = 10 % 5

5 = 5 % 10

Example: How to find the remainder without using the modulus operator in c.


#include<stdio.h>

int main() {

  int a, b;

  printf("Enter two numbers:");
  scanf("%d%d", &a,&b);

  while (a >= b) {
    a = a - b;
  }

  printf("Remainder is:%d", a);

  return 0;
}

Output:

Enter two numbers:9 2                                                                                                                                               
Remainder is:1