Posts

Showing posts with the label factorial of a number

Basic Program #3

Image
3.Read any number and find factorial of a number. (Using Recursion) #include <stdio.h> long long int factorial(int n); int main() {     int n;    long long int f;     printf("Enter an integer to find it's factorial: ");     scanf("%d", &n);      // show error if the user enters a negative integer     if (n < 0)     {         printf("Error! Factorial of a negative number doesn't exist.\n");     }     else     {              f=factorial(n);             printf("Factorial of %d = %llu\n", n, f);     } } long long int factorial(int n) {     if (n>=1)     {         return n*factorial(n-1);  ...

Basic program #2

Image
2. Read any number and find factorial of a number. (Using Loop) #include <stdio.h> int main() {     int n, i;     unsigned long long factorial = 1;     printf("Enter an integer to find it's factorial: ");     scanf("%d",&n);      // show error if the user enters a negative integer     if (n < 0)         printf("Error! Factorial of a negative number doesn't exist.");     else     {            i=1;         while(i<=n)         {             factorial *= i;              // factorial = factorial*i;             i++; ...