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 124 views
1 answer 174 views
1 answer 155 views
1 answer 135 views
135 views asked Dec 28, 2020 by avibootz
2 answers 125 views
1 answer 203 views
3 answers 132 views
...