/*
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.
Please do comment and share.
Thank You.
No comments:
Post a Comment