Power End

C Program to find list of 4 digit numbers that when raised to any power end in same 4 digits?

I have to write a C program for computer science class that finds and lists all 4 digit numbers that when raised to any power end in same 4 digits. I have no idea where to even start. Any suggestions?

Gosh, just two simple FOR NEXT loops should do it.

The inner loop is the power you're raising the number to.
The outer loop is the original number (1111 to 9999)

Sorry, I don't know the C syntax. But here's your program in BASIC, for powers up to and including 5:

FOR x = 1111 TO 9999
...FOR y = 2 TO 5
......z = x^y
......a$ = STR$(z) : b$ = STR$(x)
......IF RIGHT$(a$, 4) = RIGHT$(b$, 4) THEN
.........PRINT b$; " "; : PRINT y
......END IF

If you can read BASIC, just convert this to C syntax.

Here's the output of the program above:

1,249 3
3,751 3
4,375 3
4,999 3
5,001 3
5,625 3
6,249 3
8,751 3
9,375 3
9,376 2
9,376 3
9,999 3

The first number is the original number. The second number listed is the "power."

If you check, you can see the program is working as intended. For example, 8,751^3 = 670,151,588,751. 8751 = 8751

Notice 9,376 appears twice. Pretty cool. That's probably a puzzle answer of some kind. ("What is the only four digit number that when raised to the 2nd or 3rd power..." etc.)

Find Power End On eBay Below:

Recently Purchased Power End:

new nov wheatley 11d2 p100 power end assembly, new fmc triplex pump power end ceramic cylinder 1241364, gardner denver water jetting 431404001 power end, new gardnerdenver triplex tqc complete power end assembly pw3, new gardnerdenver tac ta3 plunger pump power end assy

Comments are closed.