0
Simple question
PROBLEM Write a C++ program to compute the powers of 2. The program must take a single integer number 'n' as input and print the value of 2 raised to the power 'n'. INPUT FORMAT A single integer ranging from 0 to 30 (Both Inclusive) You need to ensure that you handle all values within this range. You are not required to verify that the input integer in within range or not. CONSTRAINTS 0 <= n <= 30 OUTPUT FORMAT Output a single integer denoting the value of 2 raised to the power n SAMPLE EXAMPLE: Input - 4 Output - 16 (computed as 2^4 = 2*2*2*2)
2 odpowiedzi
+ 3
#include <cmath>
#include <iostream>
int main(){
int value;
std::cin >> value;
std::cout <<pow(2,value);
return 0;
}
+ 3
#include <iostream>
int main() {
unsigned v;
std::cin >> v;
std::cout << (1<<v);
return 0;
}
*Hope this is not your Homework, lol.*