factorial output

This is a discussion on factorial output within the C Programming forums, part of the General Programming Boards category; how can i get my output of a factorial to look like this: Enter a number: 5 Factorial expansion phase: ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    43

    factorial output

    how can i get my output of a factorial to look like this:

    Enter a number: 5
    Factorial expansion phase:
    5
    4
    3
    2
    1
    Factorial wrapup phase:
    1
    2
    6
    24
    120
    The factorial of 5 is 120.

    im using the function below to find factorial:

    int factorial(int n)
    {
    if (n == 0)
    return 1;

    else
    return (n * factorial (n - 1));
    }

  2. #2
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    getting there!!!

    #include <stdio.h>

    int factorial(int same){....}

    int main(void)
    {
    int origi,other,fact;

    printf("Enter a Number: ");

    scanf("%d",&other);

    origi = other;

    printf("Factorial Expansion phase: \n");

    do{
    other--;
    printf("%d\n",other);
    }while(other >= 1);

    printf("Factorial Wrapup phase: \n");

    do{
    other++;
    fact = factorial(other);
    printf("%d\n", fact);
    }while(other >= origi);

    printf("The factorial of %d is %d\n",other,fact);

    return 0;
    }
    Last edited by bljonk; 03-13-2002 at 03:32 PM.
    Ünicode¬>world = 10.0£

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. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  3. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  4. Factorial
    By foxman in forum Contests Board
    Replies: 27
    Last Post: 07-11-2008, 07:59 PM
  5. Recursion
    By Lionmane in forum C Programming
    Replies: 11
    Last Post: 06-04-2005, 01:00 AM

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