+ 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 Réponses
+ 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