how can i make a code for power by for loop ?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how can i make a code for power by for loop ??

26th Dec 2016, 7:51 PM
Nada Ali
Nada Ali - avatar
4 Answers
+ 1
Define a variable for your Base value, the power value and the result. Set the result to your Base value. give your FOR iterator the value of 2, the condition is that it is smaller or equal your power and iterate ithe iterator variable by 1. In your For loop multiply the Base value on your result value. thats it.
27th Dec 2016, 2:39 AM
Andreas K
Andreas K - avatar
+ 1
we do not appreciate to give you the complete solution in code. Because we want to support you on learning to solve these things by your own so here is a part of the code int base; // set the Base like you need it int power; // set the power like you need it int result = base; // equal to the power of 1 for( int i = 2; i <= power; i++) { // multiply the base onto the result } // The result now contains your solution of the calculation
27th Dec 2016, 11:53 AM
Andreas K
Andreas K - avatar
0
give me code plz??
27th Dec 2016, 11:35 AM
Nada Ali
Nada Ali - avatar
0
thank you very much 😊😊
27th Dec 2016, 12:17 PM
Nada Ali
Nada Ali - avatar