Please help quickly

This is a discussion on Please help quickly within the C++ Programming forums, part of the General Programming Boards category; Code: int Factorial ( int number ) // Pre: number is assigned and number >= 0. { if ( number ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    5

    Please help quickly

    Code:
    int   Factorial (  int   number )		
    //   Pre:   number is assigned and  number >= 0.
    {
         if  ( number == 0)			//  base case
    		return  1 ;
    	else					// general case
    
    
    	return  (number * Factorial ( number - 1 ));
    }
    please Switch if statment to for loop

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Oh come one... you can figure that out for yourself... can't you?

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    For asking a "quick help" you can get a quick ignore.

    What are you having problem with? Do you know what this code does?

    Code:
    unsigned int Factorial(unsigned int number)
    {
        unsigned int x = 1;
        for (unsigned int i = 2; i <= number; i++)
        {
            x *= i;
        }
        return x;
    }
    I never put signature, but I decided to make an exception.

  4. #4
    Registered User
    Join Date
    May 2011
    Posts
    5
    I figured that and I get theis :


    Code:
     
    int fac(int i)
    {
      int ret = 1;
      for(;i>1;--i)
        ret *= i;
      return ret;
    }

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    5
    Quote Originally Posted by kmdv View Post
    For asking a "quick help" you can only get a quick ignore.

    Whata re you having problem with? Do you know what this code does?

    Code:
    unsigned int Factorial(unsigned int number)
    {
        unsigned int x = 1;
        for (unsigned int i = 2; i <= number; i++)
        {
            x *= i;
        }
        return x;
    }





    Thanx, you are very cool
    I'm only a beginner

  6. #6
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    It's correct and I guess it wasn't that hard. Next time you should post your results along with the assignment.
    I never put signature, but I decided to make an exception.

  7. #7
    Registered User
    Join Date
    May 2011
    Posts
    5
    my code is correct? or what

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    Next time you should post your results along with the assignment.
    Out of curiosity, if that is the way you feel, why did you do it for him this time?

    Soma

  9. #9
    Registered User
    Join Date
    May 2011
    Posts
    5
    so , what about your code?

    is it true ?

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    4,415
    O_o

    If you know that the recursive version is correct, why don't you just compare the results of both versions up to 12 or 13 or so?

    Soma

  11. #11
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    Quote Originally Posted by phantomotap View Post
    Out of curiosity, if that is the way you feel, why did you do it for him this time?
    I did not want to see next thread with a simple question, dragging on forever, instructing the newcomer how he should ask questions the smart way. Anyway, I did not avoid it, cuz it already reaches the 10th reply.

    Quote Originally Posted by Needle_Scratch View Post
    is it true ?
    Yes, both are "true", I wouldn't post false code.
    Last edited by kmdv; 05-30-2011 at 01:27 AM.
    I never put signature, but I decided to make an exception.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help..quickly
    By digy in forum C Programming
    Replies: 25
    Last Post: 05-30-2003, 01:19 AM
  2. need help quickly
    By ver in forum C Programming
    Replies: 3
    Last Post: 03-24-2003, 05:41 PM
  3. Reading from a file quickly
    By PJYelton in forum C++ Programming
    Replies: 5
    Last Post: 10-11-2002, 02:12 PM
  4. Copying Files Quickly
    By Dan in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 03-31-2002, 04:18 AM
  5. need help quickly, going insane with this
    By Mkk84 in forum C++ Programming
    Replies: 2
    Last Post: 01-13-2002, 10:58 AM

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