I'm trying to put together an algorithm in C to find integers that change places by multiplying by another.
I did not find problems like this on the internet, I do not even know if I can do this with integers. But a brief example with fractional numbers is: 12 * 1.75 = 21
For four-digit numbers; 1489, should be 9148.
I wanted your help not to receive a complete code, but rather a path / logic to follow to develop the code.
The way I'm thinking is the following:
a variable "counter = 1". a while body to find numbers that change places between 1 and 1 million. The multiplication numbers for tests are only 2, 3, 4, 5, 6, 7, 8 and 9. Instead of using ++ counter, use counter + = nTest;
Notes
I'm a beginner in programming. I can not find which condition to use to know if the number has changed position or not. I have not yet studied array's in C, so my code will only find a single number and display it. If I knew array's, I could go storing all the numbers I find up to a million and then display all of them. I tried to explain my doubt, but if you do not understand any part, just leave a comment.
Thank you.
The following code is quite early in what I'm trying to do;
#include <stdio.h>
#include <locale.h>
int main(int argc, char const *argv[]) {
setlocale(LC_ALL, "");
//Número inteiros.
int u, d, c, m, md, mc, mi, contador;
//Números de testes para multiplicação.
int nTeste;
/*int iU, iD, iC, iM, iMD, iMC, iMI, total;*/
/*Variáveis para extrair os dígitos de cada posição.
Ex: Para extrair "2" de "21"; "tempDecimal = 21 / d".*/
u = 1; //Unidades
d = 10; //Dezenas
c = 100; //Centenas
m = 1000; //Milhar
md = 10000; //Dezenas de milhar
mc = 100000; //Centenas de milhar
mi = 1000000; //Milhão
while (nTeste >= 2 && nTeste <= 9) {
printf("Digite um número para teste: [2 a 9]");
scanf("%d", &nTeste);
}
while (contador <= mi) {
if (contador <= u) {
}
if (contado > u && contador <= d) {
}
if (contado > d && contador <= c) {
}
if (contado > c && contador <= m) {
}
if (contado > m && contador <= md) {
}
if (contado > md && contador <= mc) {
}
if (contado > mc && contador <= mi) {
}
}
return 0;
}