New Android apps UniqueKey

Saturday 21 March 2015

Inline Function

Inline function: whenever we use inline function in our program, and whenever compiler executes inline function, each time it create a copy of function code and execute the functions.
for use inline function you just have to write "inline" in front of function name.  

#include<iostream>
using namespace std;

inline float area(float radius)
{
  return 3.14*radius*radius;
}

inline float peri(float radius)
{
  return 2*3.14*radius;
}

inline float simple(float amount,float interest,int year)
{
  return amount*(interest/100)*year;
}

main()
{
  int year;
  float amount,radius,interest;
  cout << "Enter radius: ";
  cin >> radius;
  cout << "Area : " << area(radius)<<endl;
  cout << "Perimeter : " << peri(radius)<<endl;
  cout << "Simple Interest Calculator" << endl;
  cout << "Amount: "<<endl;
  cin >> amount;
  cout << "Interest (in %): ";
  cin >> interest;
  cout << "Year: ";
  cin >> year;
  cout << "Simple interest: "<< simple(amount,interest,year)<<endl;
}

No comments:

Post a Comment