Divide two values without using divide or multiply operator using c++ and ruby */
Using c++;
#include"bits/stdc++.h"
int main(){
int t,p,y,cnt=0;
scanf("%d%d%d",&y,&t,&p);
while(y--){ //t=>dividend p=>divisor
while(1){
if(t>=p){ //our need should be follow in this way...process this condition //untill t is lesser than divisor(p)
cnt+=1;
t-=p;}
else{break;}
}
printf("%d\n",cnt);}
return 0;}
Using ruby;
#instruction will be follow as above code....
y,t,p=gets().split(" ").map{|m| m.to_i}
while(y>0);
while(1);
if(t>=p)
cnt+=1
t-=p
else
break
end
end
puts cnt
end
Most imp point related to above codes;
1.above code only return floor values.
2.for accurate value use this formula a/b=exponential(log(a)-log(b))
that's all
Using c++;
#include"bits/stdc++.h"
int main(){
int t,p,y,cnt=0;
scanf("%d%d%d",&y,&t,&p);
while(y--){ //t=>dividend p=>divisor
while(1){
if(t>=p){ //our need should be follow in this way...process this condition //untill t is lesser than divisor(p)
cnt+=1;
t-=p;}
else{break;}
}
printf("%d\n",cnt);}
return 0;}
Using ruby;
#instruction will be follow as above code....
y,t,p=gets().split(" ").map{|m| m.to_i}
while(y>0);
while(1);
if(t>=p)
cnt+=1
t-=p
else
break
end
end
puts cnt
end
Most imp point related to above codes;
1.above code only return floor values.
2.for accurate value use this formula a/b=exponential(log(a)-log(b))
that's all
No comments:
Post a Comment