Thursday, July 9, 2009

What is the syntax for writing P=A(1+r)^n in 'C' language?

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





main()


{


float P,A,r,n;





Printf("Enter Amount : ");


scanf("%f",%26amp;A);


Printf("\nEnter Rate : ");


scanf("%r",%26amp;r);


Printf("\nEnter Time : ");


scanf("%f",%26amp;t);


P = A * pow(1+r,n);


printf(" \nValue of P = ",P);


}

What is the syntax for writing P=A(1+r)^n in 'C' language?
#include%26lt;stdio.h%26gt;


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


void main()


{


int p,r,n,a,i;


clrscr();


printf("Input the value of r: ");


scanf("%d",%26amp;r);


printf("\n\nInput the value of n: ");


scanf("%d",%26amp;n);


printf("\n\nInput the value of A: ");


scanf("%d",%26amp;a);


p=1;


for(i=1;i%26lt;=n;i++)


p=p*(1+r);


p=p*a;


printf("\n\nA(1+r)^n=P=%d",p);


getch();


}
Reply:first include math.h file then use the following statement in the program





p=a*(pow((1+r),n))
Reply:the answer is 4
Reply:This may help you %26amp; reduce the size of your code





int Pow(int r, int n)


{


int temp;


int i;


int x = temp = r;


for(i = 1; i %26lt; n; i++)


{


temp = temp * x;


}


return temp;


}


call it this way from your main function


p = A * Pow((1+r), n);
Reply:P = A * pow(1+r, n);





Where 'pow' is in math.h
Reply:First include math.h





then using your logic write the equation in C syntax as:





P = A * pow(1+r, n);





pow is a power function it means the same that you want.





I hope you are satisfied.
Reply:copy and paste the following code in your editor and compile it.


P=A*pow((1+r),n).


No comments:

Post a Comment