power function in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • V Rajagopalan
    New Member
    • Sep 2006
    • 3

    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.

    [CODE=c] #include <stdio.h>
    #include <conio.h>
    main()
    {
    float a,b,c,d,f,g;
    clrscr();
    printf("Enter Amount : ");
    scanf("%f",&a);
    printf("Enter Period : ");
    scanf("%d",&b);
    printf("Enter Int : ");
    scanf("%f",&c);

    d=c/100;
    f=a * pow((1+d),b);
    printf("%.2f",f );
    getch();
    }[/CODE]
    Last edited by r035198x; Aug 22 '07, 03:28 PM. Reason: added the missing code tags
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    Originally posted by V Rajagopalan
    [CODE=c]scanf("%d",&b);
    [/CODE]
    %d should be %f.

    Also you should be including math.h to predeclare the pow function.

    Comment

    • ilikepython
      Recognized Expert Contributor
      • Feb 2007
      • 844

      #3
      Originally posted by Banfa
      %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.

      Comment

      Working...