Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include "Validations.h"
- #define TRUE 1
- int _WhenEqual(int Alg, int Number, int Times); // Prototipo da funcao _WhenEqual.
- int main(void)
- {
- int algarismo, c, count;
- int A,C,N; // Declaracao das variaveis: algarismo, c, count, A, C, N.
- algarismo=c=count=0; // Inicializacao das funcoes.
- printf("ACN: ");
- scanf("%d,%d,%d", &A, &C, &N); // Leitura de dados e atribuicao de valores as respectivas variaveis
- if( !_ValSupInf(A,0,9) || !_ValSupInf(C,0,9) || !_ValSupInf(N,1,1000)) // Se A ou C nao estiverem entre 0 e 9 e A entre 1 e 1000, !_ValSupInf = 1
- {
- printf("\n\nLimite inferior ou superior nao respeitado!\n\n\n");
- return 0;
- }
- while(count != N)
- {
- algarismo++;
- c = _WhenEqual(algarismo, A); // Quando o algarismo for igual ao A por C vezes, _WhenEqual = 1.
- if(c == C) // Se (c = _WhenEqual) = 1 prosseguir.
- count++; // Contador de vezes em que existe o numero A em C vezes... ( N ).
- }
- printff("numero e': %d", algarismo);
- return 0;
- }
- int _WhenEqual(int Alg, int Number) // Quando o Alg for igual ao Number por Times vezes, _WhenEqual = 1.
- {
- int resto, count = 0; // Declaracao das variaveis: temp, resto e count. Atribuição do algarismo a variavel temp.
- // Inicializacao das variaveis resto e count.
- while(Alg > 0) // O Ciclo acaba quando a variavel tempo atinge o algarismo 0 ou menor.
- {
- resto = Alg % 10; // A var resto e igual ao 'resto' da var temp por 10.
- Alg /= 10; // A var temp e igual a si mesma a dividir por 10.
- if( resto == Number ) // Se o resto for igual a Number, count++.
- count++;
- }
- return count; // Se o Alg nao corresponder, a funcao retorna 0.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement