EXERCISE - 2

A) Write a program that computes the simple interest and compound interest payable on principal amount(in Rs.) of loan borrowed by the customer from a bank for a given period of time (in years) at specific rate of interest. Further determine whether the bank will benefit by charging simple interest or compound interest.
B) Write a program to calculate the fare for the passengers traveling in a bus. When a passenger enters the bus, the conductor asks "What distance will you travel?" On knowing distance from passenger (as an approximate integer), the conductor mentions the fare to the passenger.

A) AIM: Write a program that computes the simple interest and compound interest payable on principal amount(in Rs.) of loan borrowed by the customer from a bank for a given period of time (in years) at specific rate of interest. Further determine whether the bank will benefit by charging simple interest or compound interest.
SOURCE CODE:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
    double p,i,n,si,ci;
    cout<<"\nEnter principal amount:";
    cin>>p;
    cout<<"\nEnter interest rate:";
    cin>>i;
    cout<<"\nEnter number of terms in years:";
    cin>>n;
    si=p*(i/100)*n;
    ci=p*(pow((1+i/100),n))-p;
    cout<<"\nSimple interest is:"<<si;
    cout<<"\nCompound interest is:"<<ci;
}
OUTPUT:
Enter principal amount: 10000
Enter interest rate: 5
Enter number of terms in years: 3
Simple interest is: 1500
Compound interest is: 1576.25

B) AIM: Write a program to calculate the fare for the passengers traveling in a bus. When a passenger enters the bus, the conductor asks "What distance will you travel?" On knowing distance from passenger (as an approximate integer), the conductor mentions the fare to the passenger.
SOURCE CODE:
#include<iostream>
using namespace std;
int main()
{
    double distance,fare;
    cout<<"Enter distance to travel:";
    cin>>distance;
    fare=distance*0.5+6;
    cout<<"\nPassenger fare is "<<fare;
}
OUTPUT:
Enter distance to travel: 10
Passenger fare is 11

No comments:

Post a Comment

Total Pageviews