/*
This is the sixth lab of Lab EE107
The purpose of this lab understand how a program can generate and display a table of n and n2, for
integer values of n ranging from 1 to 10 in C.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: Feb 20, 2024.
    */
#include <stdio.h>

int main() {
    // Print column headings
    printf("This table displays the numbers geneated for n and n_squared\n");
    printf("Table for roots of n\n\n");
    printf("n\t\t n^2\n");                 //"\t" is the number of tabs for spacing
    printf("--------------------\n");

    // Generate and display a table of n and n^2 for n ranging from 1 to 10
    for (int n = 1; n <= 10; n++) {
        // Calculate the square of n
        int n_squared = n * n;

        // Print the values of n and n^2 in a tabular format
        printf("%d\t\t %d\n", n, n_squared);
    }

    return 0;
}

Embed on website

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