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.

Your factorial function should be somewhat like:

void factorial(int x)

{

int i,fact = 1;

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

fact = fact * i;

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

}

Thus this will calculate factorial of a number 'x' that is passed to this function and also print the factorial.

Dhyanesh