Advertisement
WeltEnSTurm

Untitled

Sep 30th, 2010
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. double t[10000]={};
  8. int idx=0;
  9.  
  10. double step(double x, double y){
  11.     if(floor(x/2)!=x/2){
  12.         t[idx]=y;
  13.         idx++;
  14.     }
  15.     if(x==1){
  16.         double temp=0;
  17.         for(int i=0;i<=idx;i++)
  18.             temp=temp+t[i];
  19.         return temp;
  20.     }else{
  21.         x=floor(x/2);
  22.         y=y*2;
  23.         return(step(x,y));
  24.     }
  25.     return 0;
  26. }
  27.  
  28. int main(){
  29.     while(true){
  30.         cout<<"enter 2 numbers separated with space"<<endl;
  31.         double in1=0;
  32.         double in2=0;
  33.         cin>>in1>>in2;
  34.         cout<<step(in1,in2)<<endl;
  35.         for(int i=0;i<10000;i++)
  36.             t[i]=0;
  37.         idx=0;
  38.     }
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement