Write a C program computing the interest of $100 invested at different rates of interest.
Sure, here's an example of a C program that calculates the interest of $100 invested at different rates of interest:
```c
#include <stdio.h>
int main() {
float principal = 100.0;
float rates[] = {0.05, 0.1, 0.15}; // Array to store different interest rates
int num_rates = sizeof(rates) / sizeof(float); // Calculate the number of rates
printf("Interest Calculation\n\n");
for (int i = 0; i < num_rates; i++) {
float interest = principal * rates[i];
float total_amount = principal + interest;
printf("Rate: %.2f%%\n", rates[i] * 100);
printf("Interest: $%.2f\n", interest);
printf("Total amount: $%.2f\n\n", total_amount);
}
return 0;
}
```
In this program, we first declare the principal amount as $100 and the different interest rates in an array called `rates`. We also calculate the number of rates using the formula `num_rates = sizeof(rates) / sizeof(float)`.
Inside the `for` loop, we calculate the interest by multiplying the principal with the current interest rate (`principal * rates[i]`). Then, we calculate the total amount by adding the principal and the interest (`principal + interest`).
Finally, we print the rate, interest amount, and the total amount using `printf()`.
To run this program, save it with a ".c" extension (e.g., `interest.c`) and compile it using a C compiler (e.g., GCC). Running the compiled program will display the interest and total amount for each given rate.