Ask Experts Questions for FREE Help !
Ask
    Rubentheran's Avatar
    Rubentheran Posts: 35, Reputation: 1
    Junior Member
     
    #1

    Jul 18, 2011, 11:52 AM
    Computer programming in factorial.Need help
    Question is in attachment because I can't post the image here.The question is in the attachment.Currently, I don't know how to start because its very difficult.I even studied the textbook and references but I'm still unable to solve it.Can someone help me this out by giving the guide to start.I really desperately need help because next week my exam is coming.So I need solution with working or source code from you guys for this question so that I able to refer it as guide and also able to use this solution to solve other problems .Currently I'm using Dev C++ program as compiler.
    Attached Images
     
    slapshot_oi's Avatar
    slapshot_oi Posts: 1,537, Reputation: 589
    Ultra Member
     
    #2

    Jul 18, 2011, 02:29 PM
    Are you in college, or high school? This is like every programmers first problem. Did you even try to Google the answer?

    I didn't compile and check this, but I'm pretty sure this will work.

    [CODE=C]
    #include <stdio.h>

    int factorial ( int n);

    int main ( int argc, char ** argv) {
    int n = 0;
    int i = 0;
    int product = 0;

    /* Scan std input and store the value into the address of n */
    scanf ("%d", &n);

    printf ( " n Factorial\n");
    printf ( " - ---------\n");

    product = n;

    for ( i = 1; i != n; i ++ {
    product *= ( product - i );

    printf ( " %d", i );
    printf ( " " );
    printf ( "%d", product );
    printf ( "\n" );
    }

    return 0;
    }

    /**
    *
    * This is the recursive version of the for-loop above. I'm not calling it in
    * this program. This is much faster, but I didn't use this because a) I
    * was taught only to call printf() in main() only, and 2), I couldn't figure
    * out how to use it in this context.
    *
    */
    int factorial ( int n ) {

    printf (" n");

    if ( n <= 1)
    return 0;

    return (n * factorial( n -1) );
    }
    [/CODE]

    EDIT:
    And if you have any other questions, go to Stack Overflow. The programming boards on this website are largely ignored.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Computer Science & Programming Differences [ 3 Answers ]

What are the differences? I want to work with Java, C++, Perl, and other stuff but I can't find the approprate stuff. Maybe because I'm 15. But could one of you all help me. Thanks.

Computer programming [ 2 Answers ]

How do yeah teach a computer the meaning of nothing?


View more questions Search