Russian Peasent

This is a discussion on Russian Peasent within the C Programming forums, part of the General Programming Boards category; ok so ive changed it, but im getting zero for everything now.. at least i think i fixed what u ...

  1. #31
    Registered User
    Join Date
    Sep 2008
    Posts
    101
    ok so ive changed it, but im getting zero for everything now.. at least i think i fixed what u suggested
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(floor(y/2)==1){
          
        if(fmod(y,2)==0){
    	a=a+x;
        x=x*2;
        y=(y/2);
          
        }
        else{
          x=x*2;
          y=(y/2);
    
    
      }
      }
      outD(a);
      
      }

  2. #32
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Lucid15 View Post
    ok so ive changed it, but im getting zero for everything now.. at least i think i fixed what u suggested
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(floor(y/2)==1){
          
        if(fmod(y,2)==0){
    	a=a+x;
        x=x*2;
        y=(y/2);
          
        }
        else{
          x=x*2;
          y=(y/2);
    
    
      }
      }
      outD(a);
      
      }
    Oh for crying out loud.
    Code:
    while(y!=0)
    How hard is this?

  3. #33
    Registered User
    Join Date
    Sep 2008
    Posts
    101
    ok so ive changed everything and NOW IT WORKS! i believe...
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(y!=0){
          
        if(fmod(y,2)!=0){
    	a=a+x;
        x=x*2;
        y=(y/2);
          
        }
        else{
          x=x*2;
          y=(y/2);
    
    
      }
      }
      outD(a);
      
      }

  4. #34
    Registered User
    Join Date
    Sep 2008
    Posts
    101
    Sorry for the trouble tabstop, but thank you so much for your help. Im an idiot.

  5. #35
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Call my crazy but I would probably write this same code as demonstrated bellow.

    Or maybe cleaned up to...
    Code:
    #include <FPT.h>
    int main()
    {
      double a;
      int x,y;
      x=inD();
      y=inD();
      a=0;
      while(y!=0){     
        if(!(y&3)){
          a+=x;
          x+=x;
          y/=2;    
        }
        else{
          x+=x;
          y/=2;
        }
      }
      outD(a);
    }

Page 3 of 3 FirstFirst 123
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 05-22-2009, 08:03 AM
  2. Russian student attacks Estonia
    By Perspective in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 01-25-2008, 10:35 AM
  3. Russian stuffffffffff
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 04-22-2004, 02:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21