Saturday, 20 May 2017

C/C++ Program to calculate X^N (X to the power of N) using pow function Problem Solution.


C Solution:

#include<stdio.h>
#include<math.h>
/*
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
void main(){
    int x,n,result;

    printf("Enter the value of base: ");
    scanf("%d",&x);

    printf("Enter the value of power: ");
    scanf("%d",&n);

    result = pow((double)x,n);

    printf("%d to the power of %d is = %d", x,n, result);
}

C++ Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int x,n,result;

    cout << "Enter the value of base: ";
    cin >> x;

    cout << "Enter the value of power: ";
    cin >> n;

    result = pow((double)x,n);

    cout << x << " to the power of " <<  n << " is = " << result << endl;
    return 0;
}

No comments:

Post a Comment