FACTORIAL. Can you hel me about this

This is a discussion on FACTORIAL. Can you hel me about this within the C Programming forums, part of the General Programming Boards category; what is The Code for factorial. for example i enter 10. what code i will use. i dont know the ...

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

    Smile FACTORIAL. Can you hel me about this

    what is The Code for factorial.

    for example i enter 10. what code i will use.


    i dont know the code for factorial.



    please do help me. Cause my Teacher is so strict. if i will not Pass his case study he'll be drop me. please please. i nid a cmplete code for FActorial of 10 using TURBO C. thank you. i hope someone will help me.


    THanks MelodyŁ

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What do you struggle with? Do you know how to calculate factorial in general?

    If you know how to perform the calculation itself, why don't you write down each step in English. It should then be pretty straightforward to write code to calculate it in C.

    --
    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. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,588
    What have you tried? Note that we have a homework policy: basically, we don't do your homework.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    I dont Know The code for Factorial thats why im asking for help.

    here's the question

    write a program about this computation.

    if i enter 10

    fact(10)
    fact(0)=1
    fact(1)=1*1=1
    fact(2)=2*1=2
    .... and so on.

    i dunno how to program this.

  5. #5
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    im Sorry im a new user! it will never happen again.

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

    hi.

    Hi. why i cant add you. can you add me please.

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Melody View Post
    I dont Know The code for Factorial thats why im asking for help.

    here's the question

    write a program about this computation.

    if i enter 10

    fact(10)
    fact(0)=1
    fact(1)=1*1=1
    fact(2)=2*1=2
    .... and so on.

    i dunno how to program this.
    Right, so how would you go about working out factorial for 10 by hand? Describe each of the steps.

    By the way, what laserlight meant is that we "don't do your homework for you", not that we won't help you get it done - just that YOU have to put some effort in too!

    --
    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.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    Use a for loop to count from 1 to n.
    Then multiply.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    Oh yes.! Im sorry. Im just so sad because of this. haiz. cause of my professor. he just want to program it but he dont tell us about the code. huhuhuhu. please help me.huhu. why i cant add you guys./

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Add? What do you want to do?

    --
    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.

  11. #11
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    all i know is this

    #include<stdio.h>
    int x,y;
    {
    main()
    clrscr();
    factorial fac 0 = 1
    fac n = n * fac (n-1)


    should i use X,Y for integer? or not.

  12. #12
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    i want to add the of you. but i cant. why?

  13. #13
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    The best way to do this is with a recursive function. But since you are totally new, there is no point pointing u to do it that way.

    Request the user to enter a number.

    Then scan that number into a variable.

    Then use a for loop, and an index to count down upto but not including 0.
    In that loop, here is what you must put down.

    Code:
    fact = fact*i
    where fact is the variable for factorial and i is the index.

    Then just print the result after exiting the loop.

  14. #14
    Cogito Ergo Sum
    Join Date
    Mar 2007
    Location
    Sydney, Australia
    Posts
    463
    Quote Originally Posted by Melody View Post
    all i know is this

    #include<stdio.h>
    int x,y;
    {
    main()
    clrscr();
    factorial fac 0 = 1
    fac n = n * fac (n-1)


    should i use X,Y for integer? or not.
    Yes, this is like a recursive function type, but is in no way complete. Forget doing recursive, focus on the method I just told you above

  15. #15
    Registered User Melody's Avatar
    Join Date
    Nov 2007
    Location
    Philippines
    Posts
    57
    aha, then should i use if, else statement?

Page 1 of 4 1234 LastLast
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, 10: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, 02:28 PM

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