Contact Learn C
Copy

Program 293: Program to print Compound interest for Given Years with next 4 rates in table

Program 293: Program to print Compound interest for Given Years with next 4 rates in table

Question Assignment :

#include<stdio.h>
#include<math.h>
float GetCompoundInterest(float principal,float rate,int time,int n);
main()
{ 
   float principal,rate,compoundInterest,tempRate;
   int i,n,j,time;
   principal=100; //Taking 100$ as default as for the given example
   n=1; //Indicating Compunded once per year   
   printf("Enter Interest Rate in %\n");
   scanf("%f",&rate);
   tempRate=rate;
   printf("Enter number of years\n");
   scanf("%d",&time);
   printf("Years %5.1f%% %9.1f%% %9.1f%% %9.1f%% %10.1f%%\n",rate,rate+1,rate+2,rate+3,rate+4);//To print % symbol we need to use two at a time like %%
   printf("-----------------------------------------------------------\n");
   for(i=1;i<=time;i++)
   {
     rate=tempRate;
     printf("%3d ",i);
     for(j=1;j<=5;j++)
     {
      compoundInterest=GetCompoundInterest(principal,rate,i,n);
      if(j==1)
      printf("%9.2f ",compoundInterest);
      else
      printf("%10.2f ",compoundInterest);
      rate++;
     }
     printf("\n");
   }
  
}
float GetCompoundInterest(float principal,float rate,int time,int n)
{
 float compoundInterest;
    compoundInterest=(float)(principal*(pow((1+(rate/(100*n))),(n*time))));
    return(compoundInterest);
}


Explanation:

//Coming Soon...

Output:
Program to print Compound interest for Given Years with next 4 rates in table.

Program to print Compound interest for Given Years with next 4 rates in table.






 
Donate

Download App and Learn when ever you want

Get it on PlayStore
Get it on Amazon App Store
Get it on Aptoide