+ 1
How can I raise a number to a power with loop iteration? Can you write a sample code?
number to power loop?
2 Antworten
+ 1
for(int i = 1; i < 5; i++){
System.out.println(Math.pow(2, i));
//you can also swap the 2 with i
}
0
#include <iostream>
using namespace std;
int main (void){
long b,p,r,x;
cout<<"Enter base: ";cin>>b;
cout<<"Enter power: ";cin>>p;
r = 1;
for (x=I;x<=p;x++){
r = r * b;
}
cout<<r;
}