Thread: FACTORIAL. Can you hel me about this

  1. #31
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    You can't add people on this. Even if you could, what would be the point, it's a forum, you just post messages.

    Actually, for the double format you have to use %lf

    But if you want to use %d then just change double fact to int fact

    If you don't want to use void then use:

    int main (int argc, char **argv)

  2. #32
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Melody View Post
    why like This if i view the profile of the memebers. its not working..

    vBulletin Message
    Melody, you do not have permission to access this page. This could be due to one of several reasons:

    Your user account may not have sufficient privileges to access this page. Are you trying to edit someone else's post, access administrative features or some other privileged system?
    If you are trying to post, the administrator may have disabled your account, or it may be awaiting activation.
    Why not concentrate on solving your problem? Adding people to your buddy list is not going to solve the problem.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #33
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    im sorry again.!

  4. #34
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Code:
    #include <stdio.h>
    
    int main(void) {
    int n; /* The number of fibonacci numbers we will print */
    int i; /* The index of fibonacci number to be printed next */ 
    int current; /* The value of the (i)th fibonacci number */
    int next; /* The value of the (i+1)th fibonacci number */
    int twoaway; /* The value of the (i+2)th fibonacci number */
    
    printf("How many Fibonacci numbers do you want to compute? ");
    scanf("&#37;d", &n);
    if (n<=0)
    printf("The number should be positive.\n");
    else {
    printf("\n\n\tI \t Fibonacci(I) \n\t=====================\n");
    next = current = 1;
    for (i=1; i<=n; i++) {
    printf("\t%d \t %d\n", i, current);
    twoaway = current+next;
    current = next;
    next = twoaway;
    }
    }
    return 0;
    }
    like this. is this corect?

  5. #35
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    I thought you were working on the factorial problem?

    I don't even know how or what the fibonnaci series is, so I can't help you with that.

  6. #36
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    yea/ my code for Factorial is this

    Code:
    printf("\nFor X = &#37;d\t\t", x);
    		printf("X!(factorial) = %ld",fact(x));
    		break;
    is this correct.

  7. #37
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57

    Unhappy

    Quote Originally Posted by Melody View Post
    yea/ my code for Factorial is this

    Code:
    printf("\nFor X = %d\t\t", x);
    		printf("X!(factorial) = %ld",fact(x));
    		break;
    is this correct.
    is this corect should i use scanf?

  8. #38
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    It is correct providing your function

    fact(x)

    is also correct.

    Post your whole code and not segments of it.

    You are making this far more complicated than it actually is.

  9. #39
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    okay.

  10. #40
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    cant undertsand. haiyzzzzz help me please. the whole. coz its verry rush.

  11. #41
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    We can't help you if you don't post the code, you just posted some segment. Post your whole code.

  12. #42
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is your current code for computing factorial? Please indent it properly.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #43
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Code:
     int n)
    {
       if (n == 0)
      return 1;
       else
      return n * Factorial (n - 1);
    }

  14. #44
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Quote Originally Posted by Melody View Post
    Code:
     int n)
    {
       if (n == 0)
      return 1;
       else
      return n * Factorial (n - 1);
    }
    The problem is i dont know where will i put the given number which is 10?

  15. #45
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    That's the factorial method.

    So now in the main function, request the user to enter a number.
    Scan that number, and send that number to the factorial function.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault using recursion to find factorial
    By kapok in forum C++ Programming
    Replies: 4
    Last Post: 02-23-2009, 11:10 AM
  2. Factorial
    By foxman in forum Contests Board
    Replies: 27
    Last Post: 07-11-2008, 06:59 PM
  3. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 12:00 AM
  4. Basic Factorial from 1-10
    By AaA in forum C Programming
    Replies: 20
    Last Post: 05-28-2005, 07:39 AM
  5. factorial output
    By maloy in forum C Programming
    Replies: 1
    Last Post: 03-13-2002, 03:28 PM