Key Features

Experienced Teachers
Smart Classes
Regular Test
Study Material

Well qualified teachers with industrial experience.

To visualise or understand topics very easly.

We are organizing online and offline regular test.

We are providing prescribed study material.

Friday, October 30, 2020

Write a C Program to find the factorial of a number.

Question :  Write a C Program to find the factorial of a number.
/*
Write a C Program to find the factorial of a number.
*/

#include <stdio.h>
int main()
{
            int n, i;
            unsigned long long fact = 1;
            printf("Enter an integer: ");
            scanf("%d", &n);
            // shows error if the user enters a negative integer
            if (n < 0)
            {
                        printf("Error! Factorial of a negative number doesn't exist.");
            }
            else
{
                        for (i = 1; i <= n; ++i)
{
                         fact *= i;
                        }
             printf("Factorial of %d = %llu", n, fact);
            }
    return 0;
}

OUTPUT :
Enter an integer: 10
Factorial of 10 = 3628800

Thank you very much for reading carefully, if you have any other questions, you can share it with us through comments, if this information was important to you, please let us know through comments.

Please do comment and share.
Thank You.

No comments:

Post a Comment