i need to work out the factorial of a positive integer. ie the number multiplied by all the integers smaller than it down to 1. eg "5" = 5*4*3*2*1 = 120.

i also need to incorporate a test harness.

the code i have written works out teh factors of any given number but i am not sure off how to work out the final answer. ie. how to multiply them together.

#include<stdio.h>

void main (void){

int num,x;

void factorial(int);

printf("Please enter an integer: ");

scanf("%d", &num);

fflush(stdin);

for(x=1; x<num; x++)

factorial (x);

}

void factorial (int x){

printf("x = %d\n", x);

help would b much appreciated. cheers.

void main (void){

int num,x;

void factorial(int);

printf("Please enter an integer: ");

scanf("%d", &num);

fflush(stdin);

for(x=1; x<num; x++) /* A */

factorial (x);

}

void factorial (int x){

printf("x = %d\n", x);

At A it looks like you are going to be calculating separate factorials for each x from 1 to num. So for 1 you get 1, for 2 you get 2, for 3 you get 6 for 4 you get 24 etc. Is that what you want?

The factorial function itself needs to multiply all the numbers from itself down to 1. So a loop is indicated:

for(i=x; i>=1; --i)

{ ...

}

So inside this loop you should have a variable that you successively multiply by i to get the factorial of x.