Factorial

Factorial in C#

The factorial of a non-negative integer n, denoted by n!>, is the product of all positive integers less than or equal to n>.

The factorial of n with the next smaller factorial:

$$n! = n x (n - 1) x (n - 2) x (n - 3) x \cdots x 3 x 2 x 1$$

Binary Search is a search algorithm that finds the position of a target value within a sorted array.

$$n! = n . (n -1) . (n - 2) \dots 3 . 2 . 1$$

$$n! = n . (n - 1)!$$

$$n! = \prod_{i = 1}^{n} i.$$

example: $$5! = 5 . 4! = 5.4.3! = 120$$


#include <stdio.h>

//function definition
double factorial(double a);

int main(){
    double a=98;

    //function calling
    double ans=factorial(a);
    printf("%f!:    %f\n", a, ans);
    return 0;
}

This is the factorial() function.



//function to compute factorila n! = n.)n - 1)!
double factorial(double a){
    if (a<=1){
        return 1;
    }

    //we use recursion
    return a*factorial(a-1);
}


Now read this

Fibonacci Series

C programming language,... Continue →