Program Console Vignaankosh.com
Execution Panel
Console is empty.
Factorial of a number using recursion is an interactive C dry run visualizer from the Recursion programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.
This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.
#include <stdio.h>
// Function to calculate factorial using recursion
long long int factorial(int n)
{
if (n == 0 || n == 1) // Base case
return 1;
else
return n * factorial(n - 1); // Recursive call
}
int main()
{
int num;
long long int fact;
printf("Enter a number: ");
scanf("%d", &num);
if (num < 0)
{
printf("Factorial is not defined for negative numbers.\n");
}
else
{
fact = factorial(num);
printf("Factorial of %d = %lld\n", num, fact);
}
return 0;
}