Thread: FACTORIAL. Can you hel me about this

  1. #46
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,401
    At a glance, that does not compile. Fix it such that it compiles (hint: the first line is already problematic).
    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

  2. #47
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by Melody View Post
    The problem is i dont know where will i put the given number which is 10?
    Where do you call the function? In the main right?

    So define a variable.

    int x = 10;

    Then call the factorial function with fact(x);

    Or whatever the name of the function is.
    It's just basic maths...or common sense.

  3. #48
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Me thinks you are just copying from somewhere without understanding it, perhaps from some friend or some other source or something.

    There is no way you would be doing a recursive function and not understanding variables and how to pass a value into another function.

    You should have to stuck to a simple for loop.

  4. #49
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Code:
    include<stdio.h>
    main()
    int n;
    clrscr();
    {
    printf("Enter a Number");
    scanf("%d,&n);
      if (n == 0)
      return 1;
       else
      return n * Factorial (n - 1);
    }
    getch();
    like that>

  5. #50
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by Melody View Post
    Code:
    include<stdio.h>
    main()
    int n;
    clrscr();
    {
    printf("Enter a Number");
    scanf("%d,&n);
      if (n == 0)
      return 1;
       else
      return n * Factorial (n - 1);
    }
    getch();
    like that>
    Do you really think that will run?

    Compile it and see.

  6. #51
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Quote Originally Posted by Melody View Post
    Code:
    include<stdio.h>
    main()
    int n;
    clrscr();
    {
    printf("Enter a Number");
    scanf("%d,&n);
      if (n == 0)
      return 1;
       else
      return n * Factorial (n - 1);
    }
    getch();
    like that>
    im not. copying. huhu.! its in my ntbk

  7. #52
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Either case a 4 page thread on code that is only 15 lines is far too much.

    You are needlessly complicating things for yourself.

    You didn't even think about what I suggested earlier. A FOR LOOP is all you need!

  8. #53
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    i do the loop things. thanks. im sorry if was not good. thanks Then.

  9. #54
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Code:
    #include <stdio.h>
    int main (void) {
    
    double fact;
    int i;
    
    printf("Enter number\n");
    scanf("%lf",&fact);
    
    for(;; ){
      fact = fact*i;
    }
    
    return 0;
    }
    Cmon now. What needs to be in the for loop statement?

    Also what needs to be done after the for loop?

    Two very simple things.

  10. #55
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    okay THanks. brilliant. not like me

  11. #56
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    okay Thanks to al of you. i will now off.

  12. #57
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    So you got it working?

    Cheers

  13. #58
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    YES>! tomorrow again because. its already 10:31pm here. i have class tomorow at 7:30am to 6:00Pm..


    if your free add me in YM. shy_tye0 -- thats my username.

    thanks. smart! pray for me!

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