How to raise a number to the power of N in C++

2 Answers

0 votes
#include <iostream>
#include <cmath>

int main() {
    int N = 3;
    
    int result = pow(3, N);

    std::cout << result;
    
    return 0;
}




/*
run:

27

*/

 



answered May 8, 2021 by avibootz
0 votes
#include <iostream>
#include <cmath>

int main() {
    double base = 3, exponent = 5.1;
	
	double result = pow(base, exponent);

    std::cout << result;
    
    return 0;
}




/*
run:

271.218

*/

 



answered May 8, 2021 by avibootz

Related questions

1 answer 111 views
1 answer 165 views
1 answer 146 views
1 answer 130 views
130 views asked Dec 28, 2020 by avibootz
2 answers 116 views
1 answer 183 views
3 answers 119 views
...