Write a C Program to fine the Compound Interest
![Write a C Program to fine the Compound Interest Compound Interest, Sumit Kar, C Program, Timus Rak](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd7JUeFcGURR9T3358Yzicn60HdqsMSKqXUO3-Sxfx4K5Sqc7UgUwbzWzXCCtqRS4lZ_KrO_J8XbTe1fxRFzDQ-ZO_BYWAYQLuUNCKozi7hAbEpi0FGxITpJhJtEywftgs9V5CX1CA6O8a/s1600/c-programming-tutorial.jpg)
/*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();
}
Comments
Post a Comment