C Online Compiler
Example: C program to find the factorial of a number using for loop
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// C program to find the factorial of a number using for loop #include <stdio.h> int main() { int x, i; unsigned long long f = 1; // x denotes input number // f denotes factorial value printf("Enter an integer to find the fact::\n"); scanf("%d", &x); if (x > 0) { for (i = 1; i <= x; ++i) { f *= i; } printf("Factorial of %d = %llu\n", x, f); } else { printf("Sorry, input number should be positive number greater than 1!"); } return 0; }
5
Output
Clear
ADVERTISEMENTS