Sunday, 12 June 2016

C++ Program of Exponential using Functions

In this program we will learn how to take exponential of a variable e.g 10^2.
The code is given below.

//Code starts
#include<iostream>
#include<conio.h>

using namespace std;

int expo(int b, int p)
{
 int temp=1;        //taking a temporary variable

 for(int i=1; i<=p; i++) //for loop starts
 {
  temp=temp*b;
 }

 return temp;  //returning value of temporary variable
}


int main()   //main starts

{

 int c,d;

 cout<<"Enter Base to Find its Exponential : ";
 cin>>c;

 cout<<"Enter Power to Find its Exponential : ";
 cin>>d;

 cout<<"Answer = "<<expo(c,d); // Function calling
getch();
}
//Code ends
OUTPUT:



Share:

0 comments:

Post a Comment