Page 654 - Computer science 868 Class 12
P. 654
98 sm=temp1+temp2+ca;
99 if(sm<=1)
100 {s=Integer.toString(sm)+s;
101 ca=0;
102 }
103 else if(sm==2){
104 s="0"+s;
105 ca=1;
106 }
107 else{
108 s="1"+s;ca=1;
109 }
110 a/=10;b/=10;
111 }
112 s=Integer.toString(ca)+s;
113 return Integer.parseInt(s);
114 }
115 int minus(int a,int b){
116 String s="",sa,sb;
117 sa=Integer.toString(a);
118 sb=Integer.toString(b);
119 while(sb.length()<sa.length()){sb="0"+sb;} //making digits of minuend
and subhtrand equal
120
121 for(int i=sb.length()-1;i>=0;i--) // generating 1's complement of the number
122 { char c=sb.charAt(i);
123 if(c=='0')
124 s="1"+s;
125 else
126 s="0"+s;
127 }
128 s=Integer.toString(add(Integer.parseInt(s),1));// generating 2's complement
of the number
129 int k=add(a,Integer.parseInt(s));//adding minuend and 2's complement
130 String r=Integer.toString(k);
131 return Integer.parseInt(r.substring(1));// discarding carry
652652 Touchpad Computer Science-XII

