/*
This is the fifth 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 13, 2024.
    */
#include <stdio.h>

int main(void) {
    // Declaration of variables
    int n_EU, number_EU, triangularNumberEU, counter_EU;
    triangularNumberEU = 0;

    // Outer loop to handle five sets of input
    for (counter_EU = 1; counter_EU <= 5; ++counter_EU) {
        // Prompt user for input
        printf("What triangular number do you want to enter?\n");

        // Read user input
        scanf("%i", &number_EU);

        // Reset triangularNumberEU for each set of input
        triangularNumberEU = 0;

        // Inner loop to calculate the triangular number
        for (n_EU = 1; n_EU <= number_EU; ++n_EU) {
            triangularNumberEU += n_EU;
        }

        // Display the result for each set of input
        printf("The triangular number %i is %i\n\n", number_EU, triangularNumberEU);
    }

    return 0;
}

Embed on website

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