Divide Two Numbers Without Using Division and Modulus Operator

Write C# code to divide two numbers without using the division and modulus operator

  
Showing Answers 1 - 13 of 13 Answers

shraddha Dohare

  • Aug 3rd, 2015
 

Code
  1. span style="color: #ff0000;">"Enter Dividend:""Enter Divisor:""Quotent =0""Divided By Zero""Quetiont ={0}",c);

  2.  

  3. }

  4.  

  5.  

  6.  

  7. }

  8. }

Ken

  • Aug 12th, 2015
 

Code
  1. span style="font-style: italic;">//check the param"0"//format the param """-";

  2.         }

  3.         numerator = Math.Abs(numerator);

  4.         denominator = Math.Abs(denominator);

  5.  

  6.         //start dividing //append the number of times the denominator goes into the numerator //add a decimal places".";

  7.                 }

  8.  

  9.                 //handle the remainer by multiplying it by 10.

  10.                 numerator = numerator * 10;

  11.  

  12.                 //reset counters

  13.                 subtractCounter = 0;

  14.  

  15.                 //increment decimal counter, since we dont want an infinite loop//denominator goes into the numerator at least once. increment the counter

  Was this answer useful?  Yes

Ankita

  • Aug 27th, 2015
 

Code
  1. span style="color: #ff0000;">"Enter the number:""Enter the divisor:""quotient={0},remainder={1}",q,r);

  2.         }

  3.     }

  4. }

  5.  

  Was this answer useful?  Yes

James Tyler

  • Aug 27th, 2015
 

Code
  1. span style="font-style: italic;">// Gather user input values

  2.             Console.WriteLine("Enter an integer to divide:""Enter an integer to divide the first number by:"// Call the CheckZero method to avoid division problems.// Call the Division method on the input values and display the result." divides into " + y + " -- " + z + " times.""Invalid entry.  Cannot divide a number by zero."// Set up a counter that will function as the required answer// Run a loop that will continually sum a number with itself,

  3.             // ending the loop when the current sum is greater than or equal to the other number.// Return the counter in its current state.

  Was this answer useful?  Yes

Swapnil Mahadik

  • Jan 26th, 2016
 

Code
  1. span style="color: #006699;">java.util.*"Enter number:""Enter divisor:""Quotient:""Remainder:" +rem);

  2.  

  3.  

  4.  }

  5. }

  6.  

  7.  

  8. /*

  9. D:Javap>java WithoutO

  10. Enter number:

  11. 92

  12. Enter divisor:

  13. 4

  14. Quotient:23

  15. Remainder:0

  16.  

  17. */

  Was this answer useful?  Yes

Cristina Cimpoi

  • Feb 26th, 2016
 

Converting it to binary and using a mask

  Was this answer useful?  Yes

Varun Tripathi

  • Mar 26th, 2016
 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int OriginalDivisor =0;
int NewDivisor = 0;
int Dividend =0;
int Count = 0;
int remainder = 0;
Console.WriteLine("Please Enter the dividend");
bool IsDividendInteger = int.TryParse(Console.ReadLine() , out Dividend);
Console.WriteLine("Please Enter the divisor");
bool IsDivisorInteger = int.TryParse(Console.ReadLine(), out OriginalDivisor);
if (IsDividendInteger && IsDivisorInteger)
{
NewDivisor = OriginalDivisor;
if (OriginalDivisor != 0)
{
while (NewDivisor <= Dividend)
{
NewDivisor += OriginalDivisor;
Count++;
}
if (OriginalDivisor <= Dividend)
{
int x = (NewDivisor-OriginalDivisor) - Dividend;
if (x == 0)
{
remainder = 0;
}
else
{
remainder = NewDivisor - Dividend;
}
}
else
{
remainder = -(NewDivisor - OriginalDivisor - Dividend);
}
}
else
{
Console.WriteLine("when ever you divide a number by 0 , you get infinity as answer");
}
}
Console.WriteLine( "the Quotient is {0} and the remainder is {1}",Count ,remainder );
Console.ReadLine();
}
}
}

  Was this answer useful?  Yes

James Poulose

  • Apr 18th, 2016
 

Division is nothing but repeated subtraction. E.g 20 divided by 5 - Keep subtracting 5 from 20 until you hit 0 and the count of iterations will be your answer.

  Was this answer useful?  Yes

Thirunavukkarasu G

  • Sep 15th, 2016
 

Code
  1. span style="color: #ff0000;">"Program to Find Quotient and Remainer without using division(/) operator""The Given number {0} has Quotient {1} and Remainer={2}""The Given number {0} has Quotient {1} and Remainer={2}"

  Was this answer useful?  Yes

Samwise Galenorn

  • Oct 27th, 2016
 

Use the laws of logs

Code
  1.  

  Was this answer useful?  Yes

Ankita Kulkarni

  • Feb 12th, 2017
 

It is simple logic but how can we build code for this logic in C language?

  Was this answer useful?  Yes

Pushpa Sundar

  • Mar 16th, 2018
 

Code
  1. span style="color: #006699;">java.util.Scanner"Enter the Divident: ""Enter the Divisor: ""The Quotient is : ""The Reminder is : "+divident);

  2.  

  3.         }

  4.  

  5. }

  6.  

  Was this answer useful?  Yes

Sujit

  • Feb 18th, 2019
 

Keep on subtracting divisor from dividend until dividend is 0 and return the count as quotient.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions