program to get the remainder and quotant of given two
numbers with out using % and / operators?
Answer Posted / santhi perumal
#include<stdio.h>
#include<conio.h>
int remainder, tempdevisor ,i = 0;
int division(int,int);
int main()
{
int dividend, divisor;
int quotient;
printf("Enter the value of Dividend and Divisor\n");
scanf("%d %d",÷nd,&divisor);
tempdevisor = divisor;
quotient = division(dividend,divisor);
printf("The Quotient is %d\n",quotient);
printf("The Remainder is %d\n",remainder);
}
int division(int dividend,int divisor)
{
int quotient = 1;
i++;
if(dividend == divisor)
{
remainder = 0;
return 1;
}
else if (dividend < divisor)
{
remainder = dividend;
return 0;
}
while(divisor <= dividend)
{
divisor = divisor<<1;
quotient = quotient<<1;
}
divisor = divisor>>1;
quotient = quotient>>1;
// printf("Quotient in the %d iteration is %d\n",i,quotient);
quotient = quotient + division(dividend-divisor,tempdevisor);
return quotient;
}
| Is This Answer Correct ? | 16 Yes | 16 No |
Post New Answer View All Answers
What are the advantages of using linked list for tree construction?
Where register variables are stored in c?
When is a null pointer used?
What is the difference between a string and an array?
how to write a c program to print list of fruits in alpabetical order?
what are the advanced features of functions a) function declaration and prototypes b) calling functions by value or by reference c) recursion d) all the above
What is the difference between new and malloc functions?
What does 2n 4c mean?
What are 'near' and 'far' pointers?
What are global variables?
how to count no of words,characters,lines in a paragraph.
What is the meaning of c in c language?
Why main function is special give two reasons?
How do I get a null pointer in my programs?
Write programs for String Reversal & Palindrome check