C/C++ Program To Divide Two Numbers, Without Using Divide ('/') Operator, By Successive Subtraction Method

1 comment
 /* The Following code asks the user the number to be divided, and from which it is divided. The method utilizes the successive subtraction method from the number to be divided for obtaining the quotient & it updates a variable every time that operation is performed to obtain the quotient*/
/*C/C++ Program To Divide Two Numbers, Without Using Divide ('/') Operator, By Successive Subtraction Method*/
#include <stdio.h>
#include <stdlib.h>
void main()
{
int m,n,rem,temp=0;
printf("\nEnter number to be divided : ");
scanf("%d",&m);  //Entering the dividend
printf("\nEnter number from which to be divided : ");
scanf("%d",&n); 
//Entering the divisor
while(m>=n)
{
m = m-n;  //For Remainder
temp += 1;  //For Quotient
printf("\n%d",m); //To check the status of 'm', useful for diagnostic, safe to ignore
}
printf("\n\nQuotient is : %d",temp);
printf("\nRemainder is : %d",m);
system("pause");
}

Screenshot:
C/C++ Program To Divide Two Numbers, Without Using Divide ('/') Operator, By Successive Subtraction Method
C/C++ Program To Divide Two Numbers, Without Using Divide ('/') Operator, By Successive Subtraction Method

1 comments:

Mr.Sujit Magar said...

I want c++ code of this program