C program to calculate Compound Interest

Here’s a C program that finds the size of int, float, double, and char:

					#include <stdio.h>

int main() {
    printf("Size of int: %d bytes\n", sizeof(int));
    printf("Size of float: %d bytes\n", sizeof(float));
    printf("Size of double: %d bytes\n", sizeof(double));
    printf("Size of char: %d bytes\n", sizeof(char));

    return 0;

C Program to Find the Size of int, float, double and char
  • Explanation:

    • The program starts by including the stdio.h and math.h header files. stdio.h is needed for input and output operations, while math.h is needed for the pow function used to calculate the exponentiation.
    • Inside the main function, we declare the variables principal, rate, time, and compoundInterest as doubles to store the respective values.
    • We then prompt the user to enter the principal amount, annual interest rate, and time in years using printf statements, and we read their input using scanf statements.
    • The compound interest is calculated using the formula: compoundInterest = principal * pow((1 + rate/100), time). The pow function is used to calculate the exponentiation of (1 + rate/100) to the power of time.
    • Finally, we use a printf statement to display the calculated compound interest with two decimal places.

    When you run this program, it will prompt you to enter the principal amount, annual interest rate, and time in years. After you provide the inputs, it will calculate and display the compound interest.