C+ program, Functions of exponential, increment and addition

In this program we will find exponential, increment and addition through a function.

//Code starts

#include <iostream>

#include <conio.h>

using namespace std;

int expo(int a, int b);

int inc(int x);

int add(int a, int b);

int main()

{

int num,x;

cout<<“Enter Number for exponential”<<endl;

cin>>num;

cout<<“Enter Power of exponential”<<endl;

cin>>x;

cout<< “Exponential of ” <<num<<” is “<<expo(num,x)<<endl;

cout<<“Increament of “<<x<<” is “<<inc(x)<<endl;

cout << “Addition of “<<num<<” and “<<x<<” is “<< add(num,x);

getch();

}

int add(int a, int b)

{

int ans=0;

ans=a+b;

return ans;

}

int inc(int x)

{

x=x+1;

return x;

}

int expo(int a, int b)

{

int ans=1;

for(int i=1;i<=b;i++)

{

ans=ans*a;

}

return ans;

}

//Code Ends

Advertisements

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: