473,383 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

power function in C

By using C program i am trying to calculate compound interest. The principal amount is Rs.1000, Period 2 years, Interest is 10%. When i manually calculate it gives Rs. 1210.00. whereas by using this program it shows 14515000. I give the coding for the reference. I need some one help on this problem

thanks.

Expand|Select|Wrap|Line Numbers
  1.  #include <stdio.h>
  2. #include <conio.h>
  3. main()
  4. {
  5. float a,b,c,d,f,g;
  6. clrscr();
  7. printf("Enter Amount : ");
  8. scanf("%f",&a);
  9. printf("Enter Period : ");
  10. scanf("%d",&b);
  11. printf("Enter Int    : ");
  12. scanf("%f",&c);
  13.  
  14. d=c/100;
  15. f=a * pow((1+d),b);
  16. printf("%.2f",f);
  17. getch();
  18. }
Aug 22 '07 #1
2 2206
Banfa
9,065 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. scanf("%d",&b);
  2.  
%d should be %f.

Also you should be including math.h to predeclare the pow function.
Aug 22 '07 #2
ilikepython
844 Expert 512MB
%d should be %f.

Also you should be including math.h to predeclare the pow function.
Yea, you declared all your varaibles as floats. Either do what banfa said or, to have that value as an integer, declare b as an integer.
Aug 22 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Aaron Gallimore | last post by:
Hi, Pretty simple one I think...Is there a "power of" or squared function in C++. This is what i'm trying to achieve. (array-array)*2 this doesnt work with minus numbers so i need a square...
12
by: Roman Töngi | last post by:
I just want to raise a number to a power. e.g.: 16^2 The pow()-function of cmath seems to be not enough. I've read about valarray. Is it really so difficult? Can you give me an example. ...
9
by: Profetas | last post by:
Hi I am using this function to power numbers int power (int m, int n); int power (int base, int n) { int i, p; p = 1; for (i = 1; i <= n; ++i) p *= base; return p;
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
10
by: Magnus | last post by:
I'm migrating an applicationf from Delphi5 to C# .net Framework 2.0, but have some problems convertingt the Power function, because it is not implemented in the framework Math library. Does anyone...
5
by: mathon | last post by:
hi, i develeoped a recursive function for the power and it works fine double power(double x, int n) { if (n < 0) return 1/power(x, -n); else if (n == 0) return 1.0;
9
by: mathon | last post by:
hi, i already posted an entry because of this problem, unfortunately i havent solved it so far..:( I have created a recursion for the calculation of the power like this: double...
5
by: Gus007 | last post by:
Hi all, Need the community great support once more. :) I need to know how to calculate the power of some numbers in C, the problem is that the number is too big , and the compiler gives a...
6
by: maxthebaz | last post by:
Our machines have this requirement: if power failure occurs, many important variables are to be resumed from where they were interrupted after the machine is restarted (power on in this case). In...
8
by: skanemupp | last post by:
how do i solve power(5,1.3)? def power(nbr, po): if po==0: return 1 if po>0: return nbr*power(nbr, po-1) if po<0: return 1/power(nbr, -1*po)
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.