Dremendo Tag Line

Find remainder without modulus operator in C

scanf() - Question 19

In this question, we will see how to input 2 integer numbers in C programming using the scanf() function and find out the reminder without using modulus operator (%). To know more about scanf() function click on the scanf() function lesson.

Q19) Write a program in C to input 2 integer numbers and find out the reminder without using modulus operator (%).

Program

#include <stdio.h>
#include <conio.h>

int main()
{
    int a,b,q,r;
    printf("Enter 2 integer numbers\n");
    scanf("%d%d",&a,&b);
    q=a/b;
    r=a-(b*q);
    printf("Remainder=%d",r);
    return 0;
}

Output

Enter 2 integer numbers
5
2
Remainder=1
video-poster