Wednesday, May 20, 2020

Factorial of numbers in C


  • Program :

#include <stdio.h>
int main()
{
    int n, i;
    unsigned long long fact = 1;
    printf("\n----------------FACTORIAL OF NUMBERS----------------"); 
    printf("\nEnter an integer: ");
    scanf("%d", &n);

    if(n<0)
        printf("\nError! Factorial of a negative number doesn't exist.");
    else {
        for (i = 1; i <= n; ++i) {
            fact *= i;
        }
        printf("\nFactorial of %d = %llu", n, fact);
    }

    return 0;
}




  • Output :


No comments:

Post a Comment

Function Overloading in C++

https://monitechvenkat1620.blogspot.com Program : #include <iostream> using namespace std; int c(int x, int y) {   return...