5
For example, my variable valor
(whole type) has the value 1354, note that the number 13 appears at this numeric value. How can I identify a specific number at any other numeric value?
I’d like an example in C.
Follows the statement of the problem:
China is building a space elevator, which will allow the launch of probes and satellites to a much lower cost, making possible not only scientific research projects but also space tourism. However, the Chinese are very superstitious, and so have a very special care with the floor numbering of the lift: they do not use any number containing the digit "4" or the sequence of digits "13". Thus, they do not use the 4th floor, nor the 13th floor, nor the 134th floor, nor the 113 floor, but use 103 floor. Thus, the first floors are numbered 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, . . . Since the space elevator has many floors, and they need to number every floor of the elevator, the Chinese asked you to write a program that, given the floor, indicates the number you should be assigned to him
I’ve identified a way to check if the last digit ends with 4, follow the example:
int andar(int numero)
{
int sobra = 0;
int resultado;
sobra = numero % 10;
if (sobra == 4)
{
resultado = numero + 1;
}
else
{
resultado = numero;
}
return resultado;
}
My doubt is how to identify 13 and 4 in any number.
Do you want to know if there is a sequence of digits within the digits of a number? Have you done anything? Are you having any specific questions? Any problem with what you’re doing? Show what you tried.
– Maniero
The problem here is to identify if the last digit ends with 4, this I solved, already the one I mentioned is to identify the number 13 in a certain value, for example: 413 has the number 13 already 414 has not, there must be some mathematical function to solve this.
– gato
Just need to see if you are at the end? Or you can be in any position?
– Maniero
In any position, for example: 42134 has the 13 in this value. It’s kind of a search within a value whole.
– gato
I wouldn’t do it mathematically, I’d convert to string and would search it. So I showed how the other one did, how you’re trying to do this.
– Maniero
Was to edit the question and put the enunciated.
– gato