Sunday, October 15, 2023

C Language Program Finding Factorial Value Using Recursive Function

 #include<stdio.h>

long int fact(int n);

int main() {

    int n;

    printf("Enter a positive integer: ");

    scanf("%d",&n);

    printf("Factorial of %d = %ld", n, fact(n));

    return 0;

}

long int fact(int n) {

    if (n==1)

    return 1;

       int y=fact(n-1);

       return n*y;    

}

No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner