Thursday, June 6, 2019

Write a program to factorial of the given number

/* ***********************************************
    Write a program to factorial of the given number

 date:06-06-2019
 created by:ANIL DURGAM

*****************************************************/


#include <stdio.h>
#include <stdlib.h>


long int factorial(int n);
int main()
{
    int a,b;
    printf("enter the number\n");
    scanf("%d",&a);
    //b=factorial(a);
    printf("factorial==%ld",factorial(a));
    return 0;
}

long int factorial(int n)
{
    int i;
    long int fact = 1;
    if (n==0)
        return 1;
    for(i=n;i>1;i--)
        fact*=i;
    return fact;

}
out put:::

program 2:

#include<stdio.h>
long fact(int n);
void main()
{
    int num;
    printf("Enter a number\n");
    scanf("%d",&num);
    printf("Factorial of %d is %ld\n", num,fact(num)) ;
}
long fact(int n)
{
    if (n==0)
        return(1);
    else
        return(n*fact(n-1));

}

output::
Enter a number
12
Factorial of 12 is 479001600

Note:

please send the questions which you are facing problem in C Language.

also write interview questions which are you faced in during interview related to C Language.

so i can try to solve them and send you back.

No comments:

Post a Comment

python class topic video