P026.c (1174B)
1 /* WAP to input sum (p), rate of interest (r), time (t) and type of interest 2 ('s' for simple interest amd 'c' for compound interest). Calculate and display 3 the interest earned 4 si = (p * r * t) / 100 5 compoundInterest = p * ((1 + r / 100)^t - 1) 6 */ 7 8 #include <stdio.h> 9 #include <math.h> 10 #include <ctype.h> 11 int main() 12 { 13 double principalAmount, rateOfInterest, timePeriod, simpleInterest, compoundInterest; 14 char mode; 15 printf("Enter the principle amount, Rate of interest, Time : "); 16 scanf("%lf %lf %lf", &principalAmount, &rateOfInterest, &timePeriod); 17 printf("\nEnter the mode ('s' : simple interest, 'c' : compound interest) : "); 18 scanf(" %c", &mode); 19 mode = tolower(mode); 20 switch (mode) 21 { 22 case 's': 23 simpleInterest = (principalAmount * rateOfInterest * timePeriod) / 100; 24 printf("\nSimple Interest : %g", simpleInterest); 25 break; 26 case 'c': 27 compoundInterest = principalAmount * (pow((1 + rateOfInterest / 100), timePeriod) - 1); 28 printf("\nCompound Interest : %g", compoundInterest); 29 break; 30 default: 31 printf("\nInvalid Input"); 32 return 1; 33 } 34 return 0; 35 }