/*Using pow function*/
#include<stdio.h>
#include<math.h>
void main()
{
float p,r,i,t,ci,a;
printf("Amount : ");
scanf("%f",&p);
printf("Interest rate %: ");
scanf("%f",&r);
printf("Type the period in years: ");
scanf("%f",&t);
i=1+(r/100);
ci=pow(i,t);
ci=p*ci-p;
printf("Compounded interest is : %.2f",ci);
}
/*Using for loop*/
#include<stdio.h>
void main()
{
float p,r,i,t,ci,a;
printf("Amount : ");
scanf("%f",&p);
printf("Interest rate %: ");
scanf("%f",&r);
printf("Type the period in years: ");
scanf("%f",&t);
i=1+(r/100);
ci=1;
for(a=1;a<=t;a++)
ci=ci*i;
ci=p*ci-p;
printf("Compounded interest is : %.2f",ci);
}
/* Checking Invalid Input */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float p,t,r;
float i,compound,a;
clrscr();
printf("enter principal:\t");
scanf("%d",&p);
printf("enter rate of interest:\t");
scanf("%d",&r);
printf("enter time in years:\t");
scanf("%d",&t);
if((p<1)||(t<1)||(r<1))
printf("invalid");
else
{
a=(float)p*(pow(1+r/100.0,t));
compound=a-p;
printf("the compound interest is rs.%.2f",compound);
}
getch();
}
/*Using pow function*/
#include<stdio.h>
#include<math.h>
void main()
{
float p,r,i,t,ci,a;
printf("Amount : ");
scanf("%f",&p);
printf("Interest rate %: ");
scanf("%f",&r);
printf("Type the period in years: ");
scanf("%f",&t);
i=1+(r/100);
ci=pow(i,t);
ci=p*ci-p;
printf("Compounded interest is : %.2f",ci);
}
/*Using for loop*/
#include<stdio.h>
void main()
{
float p,r,i,t,ci,a;
printf("Amount : ");
scanf("%f",&p);
printf("Interest rate %: ");
scanf("%f",&r);
printf("Type the period in years: ");
scanf("%f",&t);
i=1+(r/100);
ci=1;
for(a=1;a<=t;a++)
ci=ci*i;
ci=p*ci-p;
printf("Compounded interest is : %.2f",ci);
}
/* Checking Invalid Input */
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
float p,t,r;
float i,compound,a;
clrscr();
printf("enter principal:\t");
scanf("%d",&p);
printf("enter rate of interest:\t");
scanf("%d",&r);
printf("enter time in years:\t");
scanf("%d",&t);
if((p<1)||(t<1)||(r<1))
printf("invalid");
else
{
a=(float)p*(pow(1+r/100.0,t));
compound=a-p;
printf("the compound interest is rs.%.2f",compound);
}
getch();
}
0 Comments