using formula in C++

In this page, two programs are given. In which real world formulas have been used,

a simple demonstration to find out simple interest

In this program, we will find simple interest

As we know that we use its formula to find out the simple interest. like

si = (principle*rate*time/100);

In this formula, we have input period, rate and time from the user.

Here is the program,

#include<iostream.h>  
#include<conio.h> 

void main() 
{
 clrscr(); 
 int si,principal,rate,time; 
 cout<<"Enter Principal, rate, time: ";
 
   cout<<"\nPrincipal: "; cin>>principal;    

   cout<<"Rate(in %) : "; cin>>rate;
 
   cout<<"Time(days) : "; cin>>time; 
 
 si = (principal*rate*time/100);
  
 cout<<"Simple interest: "<<si;
  
 getch(); 
}
OUTPUT:- 
Enter Principal, rate, time:
 
Principal : 100 
Rate(in %) : 5 
Time(days) : 2 
Simple interest: 10

In the program, we have declared three variables. such as,

int principal, rate, time, si

Where, the user has been asked for input for variables period, rate and time. suppose these input are

principal = 100
rate = 5
time = 2

and variable si store these variable’s result,

si = (principal*rate*time)/100

means,

si = (100*5*2)/100

And in the last statement, the value of variable si is printed which is 10.

Thus program is executed successfully

Here is another one program,


Convert Fahrenheit degree to Celsius 

in this program we convert fahrenheit degree to celsius

Like the program above, we will use the formula here

celsius = (farhenheit-32)*5/9;

Here is the program,

#include<iostream.h> 
#include<conio.h>
 void main() 
 {
    clrscr();
    int farhenheit,celsius;

    cout<<"Enter Fahrenheit Degree: ";
    cin>>farhenheit;

    celsius = (farhenheit-32)*5/9; // using formula

    cout<<"\nIn Celsius: "<<celsius;

  getch();
}
OUTPUT:- 
Enter Fahrenheit degree: 23
In Celsius: -5

Explanation:

In the program, we have asked the user to enter the degree farhenheit. Which will be stored in the variable farhenheit, such as,

farhenheit = 23

After this we have used the formula to get  celsius degree, so

celsius = (23-32)*5/9

And in the last statement, the value of the variable calsius is printed.

Similarly in C++, we can also create many more programs where we can use the formulas.