int power (int x, int n) { int p; for (p = 1; n > 0; n--) p = p * x; return p; }
Add a main program to prompt the user to enter a integer and the desired power then call the function, and finally print out the answer. Remember to add a function prototype.
Revision
The power to raise the integer to, n must be a positive integer. Check that the value entered is positive, if it is not do not let the user proceed until a positive value is entered (see notes on Iteration).
Now re-write the main program to call this function and then display if the array is a palindrome.
Back to Main Page for Lecture 6 |