Write a program to find the factorial of the given number using function with while loop.

/* Write a program to find the factorial of the given number using function with while loop*/

#include <stdio.h>

long factorial(int);

void main()

{

    int n,f;

    printf("Enter the number : ");

    scanf("%d",&n);

    f=factorial(n);

    printf("Factorial = %ld\n",f);

    getch();

}

long factorial(int x)

{

    long fact=1;

    while(x>1)

    {

        fact*=x--;

    }

    return fact;

}

Comments

Popular posts from this blog

Write a program to accept numerator and denominator and find the remainder without using modulus (%) operator using do..while loop.