Computer Science, asked by samarpitalds, 9 months ago

Write a program to find the division of a number without using / or % or any other math function in Java. ​

Answers

Answered by queensp73
0

Answer:

// Java program to divide a number by other  

// without using / operator  

import java.io.*;  

 

class GFG  

{  

   // Function to find division without using  

   // '/' operator  

   static int division(int num1, int num2)  

   {  

       if (num1 == 0)  

           return 0;  

       if (num2 == 0)  

           return Integer.MAX_VALUE;  

         

       boolean negResult = false;  

         

       // Handling negative numbers  

       if (num1 < 0)  

       {  

           num1 = -num1 ;  

           if (num2 < 0)  

               num2 = - num2 ;  

           else

               negResult = true;  

       }  

       else if (num2 < 0)  

       {  

           num2 = - num2 ;  

           negResult = true;  

       }  

         

       // if num1 is greater than equal to num2  

       // subtract num2 from num1 and increase  

       // quotient by one.  

       int quotient = 0;  

       while (num1 >= num2)  

       {  

           num1 = num1 - num2 ;  

           quotient++ ;  

       }  

         

       // checking if neg equals to 1 then making  

       // quotient negative  

       if (negResult)  

               quotient = - quotient ;  

       return quotient ;  

   }  

     

   // Driver program  

   public static void main (String[] args)  

   {  

       int num1 = 13, num2 = 2 ;  

       System.out.println( division(num1, num2));  

             

   }  

}  

 

// This code is contributed by vt_m.

Explanation:

hope it helps u

:)

Answered by jindaltushar2610
0

Answer:

This is for u.

Explanation:

&lt;svg width="350" height="350" viewBox="0 0 100 100"&gt;\ \textless \ br /\ \textgreater \ \ \textless \ br /\ \textgreater \ &lt;path fill="pink" d="M92.71,7.27L92.71,7.27c-9.71-9.69-25.46-9.69-35.18,0L50,14.79l-7.54-7.52C32.75-2.42,17-2.42,7.29,7.27v0 c-9.71,9.69-9.71,25.41,0,35.1L50,85l42.71-42.63C102.43,32.68,102.43,16.96,92.71,7.27z"&gt;&lt;/path&gt;\ \textless \ br /\ \textgreater \ \ \textless \ br /\ \textgreater \ &lt;animateTransform \ \textless \ br /\ \textgreater \ attributeName="transform" \ \textless \ br /\ \textgreater \ type="scale" \ \textless \ br /\ \textgreater \ values="1; 1.5; 1.25; 1.5; 1.5; 1;" \ \textless \ br /\ \textgreater \ dur="2s" \ \textless \ br /\ \textgreater \ repeatCount="0"&gt; \ \textless \ br /\ \textgreater \ &lt;/animateTransform&gt;\ \textless \ br /\ \textgreater \ \ \textless \ br /\ \textgreater \ &lt;/svg&gt;

Pls mark it the Brainliest

I need it

Similar questions