Page 655 - Computer science 868 Class 12
P. 655

132              }
                  133

                  134          void div(int n,int d)
                  135        { String q,r,

                  136            cn=Integer.toString(n);
                  137            String cd=Integer.toString(d);

                  138          int pass=0;
                  139          if(n<d)
                  140          { q="0";

                  141            r=Integer.toString(n);

                  142          }
                  143         else
                  144         {

                  145
                  146             while(cn.compareTo(cd)>=0) //numerator>denominator

                  147             { //subtracting denominator from numerator
                  148                String k=Integer.toString(minus(Integer.parseInt(cn),Integer.parseInt(cd)));

                  149               System.out.println(k);
                  150               pass++;//finding quotient

                  151               cn=k;
                  152              }

                  153              r=cn;
                  154              q=Integer.toString(tobinary(pass));

                  155              System.out.println("the quotient:"+q);
                  156              System.out.println("the remainder:"+r);

                  157          }
                  158      }

                  159        public static void main()
                  160        { binopt ob=new binopt();

                  161          ob.accept();
                  162          }

                  163      }
                 The output of the preceding program is as follows:

                 *Output*
                 Enter 2 decimal numbers:


                                                                                                                       653
                                                                                                       Sample Projects  653
   650   651   652   653   654   655   656   657   658   659   660