Q:

C program to find remainder of two numbers without using modulus (%) operator

0

C program to find remainder of two numbers without using modulus (%) operator

Given two integer numbers and we have to find the remainder without using modulus operator (%) in C.

Here, we will read two integers numbers and find their remainder. To get the remainder we will not use the modulus (%) operator.

Formulas to get the remainder,

1) Using modulus (%) operator

    rem = a%b;

2) Without using modulus (%) operator

    rem = a-(a/b)*b;

Here, a and b are the input numbers.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

C program to find the remainder of two numbers without using modulus (%) operator

/*
    * Program to get remainder without using % operator.
*/
 
#include <stdio.h>
int main()
{
    int a,b,rem;
    printf("Enter first number :");
    scanf("%d",&a);
    printf("Enter second number :");
    scanf("%d",&b);
 
    rem=a-(a/b)*b;
 
    printf("Remainder is = %d\n",rem);
    return 0;
}

Output

    Enter first number :16
    Enter second number :7
    Remainder is = 2    

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C programming Basic Input, Output, if else, Ternary Operator based Programs

Similar questions


need a help?


find thousands of online teachers now
C program to convert ascii to integer (atoi() impl... >>
<< C Example for nested \"printf\"...