Friday, May 21, 2010

C language help needed ? HELP ME ?

I am trying to make a program to calculate compound interest ?


Formula is - A=P(1+R/100)N


Here n is power.


or you can get formula on http://www.viacorp.com/compound_interest...


Can you help me to make a program.


But I cannot make a command for N.


I am at inserting power to programme.

C language help needed ? HELP ME ?
A = P(1 + r)^n





First your save P(1+r) into A


Then multiple A to itself n times (this is usually a loop).





Or just use the POW function:





pow (x,y)





x = base


y = power
Reply:This looks OK. However, if it's giving complete garbage as output, this may be because you forgot to put





#include %26lt;math.h%26gt;





at the top of your file. In C, if a function's prototype isn't declared before you use it, the return type and all the parameters' types default to int.





If it's producing results that are almost right, check your input. Where are the values of p and r coming from? If you're using scanf to get them, check your format string.
Reply:This C program computes compound interest using the FOR loop.





A person invests $500.00 in a saving account yielding 3% of interest. Assuming that all interest is left on deposit in the account, calculate and print the amount of money in the account at the end of each year for 10 years using the following equation:





a = p(1+r)n





where p is the original amount invested





r is the annual interest rate





n is the number of year





a is the amount on deposit at the end of the nth year





======================================...


/* Calculating compound interest*/





#include %26lt;stdio.h%26gt;





#include %26lt;math.h%26gt;








/* function main begins program execution */





int main()





{





double amount; /* amount on deposit */


double principal = 500.0; /* starting principal */


double rate = 0.03; /* annual interest rate */


int year; /* year counter */








/* output table column head */


printf( "%4s%21s\n", "Year", "Amount on deposit" );





/* calculate amount on deposit for each of ten years */


for ( year = 1; year %26lt;= 10; year++ ) {





/* calculate new amount for specified year */


amount = principal * pow( 1.0 + rate, year );








/* output one table row */


printf( "%4d%21.2f\n", year, amount );





} /* end for */


return 0; /* indicate program ended successfully */


}


======================================...





Good luck 2 u!
Reply:To use exponents in C, you use the function:





pow (x,y) where x is the base and y is the exponent you want to raise it to.





In your example, this would be:





A = pow (P*(1+R/100), N);





Enjoy!


No comments:

Post a Comment