/* This is the tenth lab of Lab EE107
The purpose of this lab for finding out the triangular numbers via
calling a function.
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 2nd, 2024.
*/
#include <stdio.h>
// Function to calculate triangular number
int calculateTriangularNumber_EU(int n_EU) {
return (n_EU * (n_EU + 1)) / 2;
}
int main() {
int n_EU, triangularNumber_EU;
// Input the value of n
printf("Enter the value of n to find the nth triangular number: \n");
scanf("%d", &n_EU);
// Check if the input is valid
if (n_EU <= 0) {
printf("Please enter a positive integer.\n");
return 1; // Exit with error code
}
// Calculate the nth triangular number
triangularNumber_EU = calculateTriangularNumber_EU(n_EU);
// Display the result
printf("The %dth triangular number is: %d\n", n_EU, triangularNumber_EU);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: