Advertisement
FoxTuGa

ACN

May 8th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "Validations.h"
  3. #define TRUE 1
  4.  
  5. int _WhenEqual(int Alg, int Number, int Times);     // Prototipo da funcao _WhenEqual.
  6.  
  7. int main(void)
  8. {
  9.     int algarismo, c, count;       
  10.     int A,C,N;          // Declaracao das variaveis: algarismo, c, count, A, C, N.
  11.     algarismo=c=count=0;        // Inicializacao das funcoes.
  12.     printf("ACN: ");
  13.     scanf("%d,%d,%d", &A, &C, &N);      // Leitura de dados e atribuicao de valores as respectivas variaveis
  14.  
  15.     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
  16.     {
  17.         printf("\n\nLimite inferior ou superior nao respeitado!\n\n\n");
  18.         return 0;
  19.     }
  20.  
  21.     while(count != N)
  22.     {
  23.         algarismo++;       
  24.         c = _WhenEqual(algarismo, A);       // Quando o algarismo for igual ao A por C vezes, _WhenEqual = 1.
  25.         if(c == C)      // Se (c = _WhenEqual) = 1 prosseguir.
  26.             count++;        // Contador de vezes em que existe o numero A em C vezes... ( N ).
  27.     }
  28.     printff("numero e': %d", algarismo);
  29.  
  30.  
  31.     return 0;
  32. }
  33.  
  34. int _WhenEqual(int Alg, int Number)     // Quando o Alg for igual ao Number por Times vezes, _WhenEqual = 1.
  35. {
  36.     int resto, count = 0;       // Declaracao das variaveis: temp, resto e count. Atribuição do algarismo a variavel temp.
  37.                                 // Inicializacao das variaveis resto e count.
  38.     while(Alg > 0)      // O Ciclo acaba quando a variavel tempo atinge o algarismo 0 ou menor.
  39.     {
  40.         resto = Alg % 10;       // A var resto e igual ao 'resto' da var temp por 10.
  41.         Alg /= 10;      // A var temp e igual a si mesma a dividir por 10.
  42.         if( resto == Number )       // Se o resto for igual a Number, count++.
  43.             count++;
  44.     }
  45.     return count;       // Se o Alg nao corresponder, a funcao retorna 0.
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement