+ 1

How can I raise a number to a power with loop iteration? Can you write a sample code?

number to power loop?

15th Mar 2017, 1:14 AM
Bobur
Bobur - avatar
2 Answers
+ 1
for(int i = 1; i < 5; i++){ System.out.println(Math.pow(2, i)); //you can also swap the 2 with i }
15th Mar 2017, 1:33 AM
David Koplik
David Koplik - avatar
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; }
15th Mar 2017, 6:46 AM
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender)
à€Šà„‡à€”à„‡à€‚à€Šà„à€° à€źà€čà€Ÿà€œà€š (Devender) - avatar