Friday 5 October 2012

Function018

Write a function to calculate the factorial value of a given number.

#include <stdio.h>
#include <conio.h>
long fact ( long );
void main ( )
{                          
        long n,f;
        clrscr ( );
        printf("\n\n\n\t\t Enter a number..:"); scanf("%ld",&n);
                    
        f = fact ( n );
        printf("\n\n\n\t\t Factorial value of %ld is %ld.",n,f);
        getch();
}                              
                                  
long fact ( long    n )
{                        
        long     i, f = 1;
                               
        for ( i = 1; i <= n; i++ )
        {                                        
                    f = f * i;
        }
        return f;
}
Click here to contact us 

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...