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:

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:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s