Exponentiation (only) using integer arithmetic

To raise an integer "k" to the "n"th power:

(Pseudocode)
Input to the routine:
	k
	n

set result = 1  // (Any integer raised to the "0" power = 1.)
if the power is greater than 1
	loop n times
		result = result * k

The loop is executed only on the condition that the power is greater than 0.
Advertisements

About James Johnson

I am an amateur mathematician & political theorist who enjoys (occasionally cerebral) humor.
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s