StudyLover
  • Home
  • Study Zone
  • Profiles
  • Typing Tutor
  • Contact us
  • Sign in
StudyLover Program #3 (U1): Simple Interest (SI) & Compound Interest (CI)
Download
  1. C Programming
  2. C Programming Practice
Program #2 (U1): Sum & Average + Operator Precedence : Program #4 (U1): Type Conversion — Integer Division vs Casting
C Programming Practice

Task: Read principal (P), annual rate in percent (R), and time in years (T). Compute SI = (P×R×T)/100 and CI for annual compounding using A = P × (1 + R/100)T, then CI = A − P. Print both to two decimal places.

 
/* 

  Program: Simple Interest & Compound Interest (U1)

  What it does:

    - Inputs principal P, annual rate R (in %), and time T (in years).

    - Computes: SI = (P * R * T) / 100.

    - Computes: Amount A = P * (1 + R/100)^T, then CI = A - P (annual compounding).

  Note: To compile on some systems you may need the math library: e.g., gcc file.c -o a.out -lm

*/

 
#include <stdio.h>

#include <math.h>   /* for pow() */

 
int main(void) {

    double P, R, T;        /* principal, rate(%), time(years) */

    double SI, A, CI;      /* simple interest, amount, compound interest */

 
    printf("Enter Principal (P), Rate in %% per annum (R), and Time in years (T): ");

    if (scanf("%lf %lf %lf", &P, &R, &T) != 3) {

        printf("Invalid input. Please enter three numbers like: 10000 7.5 3\n");

        return 0;

    }

 
    /* Basic validation: principal and time non-negative; rate can be zero. */

    if (P < 0 || T < 0) {

        printf("Principal and Time must be non-negative.\n");

        return 0;

    }

 
    SI = (P * R * T) / 100.0;

    A  = P * pow(1.0 + R / 100.0, T);

    CI = A - P;

 
    printf("Simple Interest (SI) = %.2f\n", SI);

    printf("Compound Interest (CI, annual) = %.2f\n", CI);

    printf("Total Amount (A) = %.2f\n", A);

 
    /* Example:

       Input: P=10000, R=7.5, T=3

       SI = 2250.00

       A  = 12421.88, CI = 2421.88

    */

 
    return 0;

}

 

 

Program #2 (U1): Sum & Average + Operator Precedence Program #4 (U1): Type Conversion — Integer Division vs Casting
Our Products & Services
  • Home
Connect with us
  • Contact us
  • +91 82955 87844
  • Rk6yadav@gmail.com

StudyLover - About us

The Best knowledge for Best people.

Copyright © StudyLover
Powered by Odoo - Create a free website