nikolas_serafini

Lista 4 - Exercício 37

Jun 25th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     int i,counter = 0;
  7.     char cpf[15];
  8.  
  9.     printf("Entre com seu cpf: (com barras e traco) :\n");
  10.     gets(cpf);
  11.    
  12.     for (i = 0; i < strlen(cpf); i++)
  13.     {
  14.         if (i == 3 || i == 7)
  15.         {
  16.             if (cpf[i] == '.')
  17.                 counter++;
  18.         }
  19.            
  20.         else if (i == 11)
  21.         {
  22.             if (cpf[i] == '-')
  23.                 counter++;
  24.         }  
  25.        
  26.         else
  27.         {
  28.             if (cpf[i] >= 48 && cpf[i] <= 57)
  29.                 counter++;
  30.         }
  31.     }
  32.  
  33.     if (counter == 14)
  34.         printf("CPF valido!\n");
  35.     else
  36.         printf("CPF invalido!\n");
  37.        
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment