i need to make a program that will identify the values of ABCDE that will result to EDCBA if you will multiply it with 4.

looks like this: ABCDE x 4 = EDCBA

i already have the values, it's 21978 x 4 = 87912

but i dont know how to make a program that can identify the values of ABCDE.

can you help me?.

Dani AI

Generated

Two practical ways to find a 5‑digit number ABCDE so that 4 * ABCDE = EDCBA: brute force (simple, tiny search space) or digit-by-digit simulation that mirrors hand multiplication and carries (fast and educational). hinted at the string approach; pointed toward carry propagation — both are valid. The easiest is brute force because there are only 15,000 five‑digit candidates to check (10000..24999), so any modern machine finishes instantly.

A minimal Python brute‑force using string reversal:

for n in range(10000, 25000):
    if str(4 * n) == str(n)[::-1]:
        print(n, 4 * n)

A C++ version that reverses integers (no strings):

#include <iostream>

int rev(int x){
    int r = 0;
    while (x > 0){
        r = r * 10 + x % 10;
        x /= 10;
    }
    return r;
}

int main(){
    for (int n = 10000; n <= 24999; ++n){
        if (rev(n) == 4 * n)
            std::cout << n << " -> " << 4 * n << '\n';
    }
}

If interested in the carry method (fewer candidate checks and mirrors manual multiplication), simulate multiplying digit-by-digit from the least significant digit, check that each product's unit matches the corresponding reversed digit, and propagate the carry. Example Python implementation:

def matches_by_carry(n):
    digits = [int(ch) for ch in f"{n:05d}"]
    carry = 0
    for i in range(4, -1, -1):          # from E toward A
        prod = digits[i] * 4 + carry
        if prod % 10 != digits[4 - i]:  # must match reversed position
            return False
        carry = prod // 10
    return carry == 0

Troubleshooting: ensure both numbers are 5 digits when comparing (restricting the range to 10000..24999 handles this). If a search returns nothing, double‑check ranges and that you treat leading zeros properly (pad if you generalize). For quick testing, brute force is sufficient; use the carry method when you want to reason about digit constraints or generalize to other multipliers.

Recommended Answers

All 4 Replies

Well there can be thousands of correct values here for the variables that you mention. For ex: ABCDE could be 4 and EDCBA could be 16, ABCDE could be 16 and EDCBA could be 64, etc, etc. So you cannot exactly get to the values that you mention.

Do you want to find out all possible values ?? I doubt.
Tell us more about your program.

no i dont want to find all the values :)

the values are static
A = 2
B = 1
C = 9
D = 7
E = 8

I assume this is an exam question, and your urgency in the PM tells me that you might actually be answering one.
I am not keen on giving answers straight up, more so in your case, because of some of my assumptions mentioned above.
I would give you the hint for this, if you are smart enough to take it, I suppose you deserve to get through.

You know how multiplication goes, since it is a single digit multiplication here (4) you can work your way this way,
Since, ABCDE * 4 = EDCBA,
A has to be ones digit of the result of E * 4.
B has to be the ones digit of the result of D * 4 + tens digit of E * 4

So to put this into prrogramming terms,
A = (E*4)%10
B = ( (D*4) + ((E*4)/10) ) % 10

I hope you are able to work your way now.

NOTE : Ignore my earlier post, as I completely misunderstood the problem.

Another approach might be to convert both the values ABCDE and 4*ABCDE to strings, reverse one of them, and use string comparison.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.