4
I’m trying to put together a C algorithm to find integer numbers that change places by multiplying by another.
I haven’t found problems like this on the Internet, I don’t even know if there’s a way to do it with whole numbers. But a brief example with fractional numbers is: 12 * 1,75 = 21
For four-digit numbers; 1489, it should be 9148.
I wanted help from you 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 += nTeste;
Remarks
I’m new to programming. I can’t find the condition to use to know if the number has changed position or not. I haven’t studied array’s in C yet, 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 them all. I tried to explain my doubt, but in case you don’t understand some part, just leave a note.
Thank you.
The following code is something very initial of how 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;
}
You have already learned to write functions (not to
main()
)?– user25930
Yes, I’m reading How to Program in C - Deitel.
– Vagnerlandio Nunes