__Practice some C++ Programs__

**Q5.**Write a C++ program to accept principal, rate of interest and time the find compound interest, simple interest and their difference.

**Q6.**Write a C++ program to evaluate the expression -

**Q7.**Write a C++ program to evaluate the following expression.

We have to learn some mathematical functions before doing such programs

pow(x,y) | x^{y} |
Evaluates x to the power y. e.g for 2^{8} we have to write pow(2,8), returned value is double type |

pow10(x,y) | x^{y} |
Evaluates 10 to the power x, x is an integer, returned value is double type |

sqrt(x) | √ x | Evaluates square root of x, x must be >=0, returned value is double type |

exp(x) | e^{x} |
Evaluates exponent of x, returned value is double type |

sin(x), cos(x), sec(x) | sin(x), cos(x), tan(x) | Evaluates sin(x), cos(x), tan(x). Here x is in radian (double), returned value is double type |

fabs(x) | |x| | Evaluates absolute value of x, x is double type, returned value is double type |

abs(x) | |x| | Evaluates absolute value of x, x is an integer, returned value is integer type |

log(x) | log_{e}x |
evaluates natural log of x, returned value is double type |

log10(x) | log_{10}x |
Evaluates log of x with base 10, returned value is double type |

**All the Mathematical functions are defined in the header file "math.h". So do not forget to include this header file in order to use any of these functions.**

__Program-5__

#include <iostream.h> #include <math.h> void main(){ float p, r, t, si, ci, diff; cout<<"Enter Principal:"; cin>>p; cout<<"Enter Rate of Interest:"; cin>>r; cout<<"Enter Time in years:"; cin>>t; si=a*b*c/100; ci=p*pow(r/100, t)- p; diff=ci-si cout<<"Simple Interest="<<si<<"\n"; cout<<"Compound Interest="<<ci<<"\n"; cout<<"Difference="<<diff<<"\n"; }

__Program-6__

#include <iostream.h> #include <math.h> void main(){ float x, y, z, result; cout<<"Enter value of x:"; cin>>x; cout<<"Enter value of y:"; cin>>y; cout<<"Enter value of z:"; cin>>z; result=pow(x,4)+ sqrt(y*y + z*z)/(y-z); cout<<"Answer="<<result; }

__Program-7__

#include <iostream.h> #include <math.h> void main(){ float a, b, x, y, result; cout<<"Enter value of a:"; cin>>a; cout<<"Enter value of b:"; cin>>b; cout<<"Enter value of x:"; cin>>x; cout<<"Enter value of y:"; cin>>y; result=fabs(a-b)*pow(a,exp(x-1)+pow((pow(x, 1/4)+pow(y, 1/7)), 1/4); cout<<"Answer="<<result; }

**Note:**In program-6 y

^{2}can be written as pow(y,2) since power is 2 we can write as it is done in the program. For large power it should be using pow() function. Another point to rember that in mathematical expressions we can use only parenthesis "( )" no other brackets allowed, we can use as many brackets as we need but must be in pair.

In program-7 the 4th root is evaluated using pow(k, 1/4), where k=pow(x, 1/4)+pow(y, 1/7).

Tweet