Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- double t[10000]={};
- int idx=0;
- double step(double x, double y){
- if(floor(x/2)!=x/2){
- t[idx]=y;
- idx++;
- cout<<idx<<endl;
- }
- if(x==1){
- double temp=0;
- for(int i=0;i<=idx;i++)
- temp=temp+t[i];
- return temp;
- }else{
- x=floor(x/2);
- y=y*2;
- return(step(x,y));
- }
- return 0;
- }
- int main(){
- while(true){
- cout<<"enter 2 numbers separated with space"<<endl;
- double in1=0;
- double in2=0;
- cin>>in1>>in2;
- cout<<step(in1,in2)<<endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment