A Program to Find Factorial of a Number
In this example, we are giving a program to find the factorial of a number.
Program to find factorial:
#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 integerif (n < 0)printf("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: 7 Factorial of 7 = 5040