Write a C Program to fine the Compound Interest



Compound Interest, Sumit Kar, C Program, Timus Rak







/*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

Popular posts from this blog

Write a Program to Add two 3x3 Matrix using C

C program for Unit Conversion

Write a Program to Add two 5x5 Matrix using C