asked 99.0k views
2 votes
3. write a loop that computes the total of the following: (no need to write a complete program) 1/30 2/29 3/28 4/27 ........... 30/1

asked
User Illiana
by
8.1k points

1 Answer

5 votes
Here's an example loop in C that computes the total of the given series:

#include

int main() {
double total = 0.0;

for (int i = 1; i <= 30; i++) {
double term = (double)i / (31 - i);
total += term;
}

printf("Total: %.2f\\", total);

return 0;
}


In this loop, we start with i as 1 and iterate up to 30. For each iteration, we compute the term as i / (31 - i) and add it to the total. Finally, we print the total after the loop completes.
answered
User Dilraj
by
8.1k points

No related questions found