/*
This is the sixth lab of Lab EE107
The purpose of this lab is to understand the interation with for loop in C
The purpose is to create the code and free of syntax and grammatical errors
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: Feb 20, 2024.
    */
#include <stdio.h>

// Function to calculate factorial
int factorial(int n) {
    if (n == 0 || n == 1) {
        return 1; // Base case: 0! and 1! are both 1
    } else {
        return n * factorial(n - 1); // Recursive case: n! = n * (n-1)!
    }
}

int main() {
    // Print the table header
    printf("n\tFactorial\n");
    printf("-----------------\n");

    // Calculate and print factorials for numbers 1 through 10
    for (int i = 1; i <= 10; i++) {
        printf("%d\t%d\n", i, factorial(i));
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: