/*
This is the fifth lab of Lab EE107
The purpose of this lab is to understand the interation with sequence for 2*n -1 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.
*/
/*Program to calculate the series for the "for" statement*/
#include <stdio.h>
int main(void) {
// Declaration and initialization
int n_EU, sum_EU;
sum_EU = 0;
// Loop to calculate the sum of the series (1 + 3 + 5 + ... + 99)
for (n_EU = 1; n_EU <= 50; ++n_EU) {
// Each term in the series is represented by 2n-1
int term_EU = (2 * n_EU - 1);
// Accumulate the terms to calculate the sum
sum_EU += term_EU;
}
// Displaying the result
printf("The sum of the series (1 + 3 + 5 + ... + 99) is %d\n", sum_EU);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: