recent posts

Factorial program in C | C programming



Hi, I'm Golam Rabbani. Today I will discuss about Factorial. Greetings! How are you all? Hope everyone is well.
At first we have to know that what Factorial is?
Factorial is a positive integer number of n. It denoted by n! And is the product of all element less than or equal to n. (Symbol:!)e.g. 4! = 4*3*2*1 = 24
So, the rule is:
n! = n*(n-1)!
If, n = 5; then we get the equation of factorial.
1. 5! = 5*(5-1)!
2. 5! = 5*4!
3. 5! = 5*4*(4-1)!
4. 5! = 5*4*3!
5. 5! = 5*4*3*(3-1)!
6. 5! = 5*4*3*2!
7. 5! = 5*4*3*2*(2-1)!
8. 5! = 5*4*4*3*2*1!
9. 5! = 5*4*3*2*1
So, 5! = 120.
Question 1: Factorial program in C
/*
            _____
           |  ___|
           | |
           | |
      __   | |___
     |__|  |_____|

    Problem Solution: 1
*/
#include<stdio.h>
// Manual Function
int valuelessfact(int n){
    int i, j=1;
    for(i=1;i<=n;i++){
        j=j*i;
    }
    return j; // Return value of j
}

int main(){
    int v;
    printf("Enter number of Factorial: ");
    scanf("%d",&v);
    printf("Factorial Result = %d ", valuelessfact(v));
    return 0;
}
Output:
Thank you

Factorial program in C | C programming Factorial program in C | C programming Reviewed by Golam Rabbani on November 25, 2018 Rating: 5

No comments:

top navigation

Powered by Blogger.