Power of a Number || Exponential Function Calculation ||C++


In this, we are going to see that if we are given a base and an exponent then find a number(base) raised to a number(exponent/power) with the help of C++ program.
Eg : base = x
        power = y
        say z = x^y
        We are goint to find this using C++ .

The Code given below can be used in Turbo C++ Compiler.


// power OR numbers raised to a number
#include<iostream.h>
#include<conio.h>
#include <math.h> 
// this is necessary for power, sqrt etc...

void main()
{
    clrscr();
    int a = 13;
    int b = 2;
    int c = pow(a, b); // a^b <== pow(a,b)
    cout<<"a ^ b = "<<c<<endl;
    
    float d = 13.2;
    float e = 2.5;
    float f = pow(d, e);
    cout<<"d ^ e = "<<f<<endl;
    getch();
}

  

The Code given below can be used in g++/gcc Compiler.

// power OR numbers raised to a number
#include<iostream>
#include <math.h> 
//this is necessary for power, sqrt etc...
using namespace std;

int main()
{
    int a = 13;
    int b = 2;
    int c = pow(a, b); // a^b <== pow(a,b)
    cout<<"a ^ b = "<<c<<endl;
    
    float d = 13.2;
    float e = 2.5;
    float f = pow(d, e);
    cout<<"d ^ e = "<<f<<endl;
    return 0;
}
  
  

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post