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

C++ program of Recursion

In this program we will clear the concept of recursion, that how a function calls it self and shows us the real value.

//Code Starts

#include<iostream>

#include<conio.h>

using namespace std;

int rf(int n)

{

if(n==1)

{

return 1;

}

else 

{

return n*rf(n-1);

Screenshot (3).png

}

int main()

{

int m;

cout<<“Enter value to find factorial : “;

cin>>m;

cout<<rf(m);

getch();

}

//Code ends

OUTPUT:

Screenshot (3).png

C++ program of Cout and Cin

In this C++ program we will print a string and asks user to insert a string in program.

//Code starts

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

using namespace std;

int main()
{
char x[30];

cout<<“Hello! Future Programmer”<<endl; //printing

cout<<“Enter your name : “;
cin>>x;

getch();

}

OUTPUT:

12