Wednesday, May 1, 2019

Write a C program To Find the Factorial Of a Given Number (n>0) Using Pointers.

PROGRAM

#include<stdio.h>
void findFact(int,long int *);
int main()
{
    long int fact;
    int num1;
    printf("Enter a number:");
    scanf("%d",&num1);
    findFact(num1,&fact);
    printf("The factorial of %d is: %d\n",num1,fact);
    return 0;
}
void findFact(int n,long int *f)
{
    int i;
    *f=1;
    for(i=1;i<=n;i++)
    {
        *f=*f*i;
    }
}

output:-



1 comment: