Saturday, 12 March 2016

Procedure 6.9B (Factorial Calculation (non-recursive way) )


Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.

/**Bismillahir Rahmanir Rahim**/

#include <stdio.h>

long long int fact(long long int n)
{
    long long int i, m = 1;
    for(i=1; i<=n; i++)
        m *= i;
    return m;
}
int main()
{
    long long int n, m;
    printf("Input a number (less than 20)\n");
    scanf("%lld", &n);
    m = fact(n);
    printf("%lld!   =    %lld\n",  n, m);
    return 0;
}


0 comments:

Post a Comment

Note: only a member of this blog may post a comment.