Advertisement
arthurcgc

Untitled

Oct 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. void valida()
  6. {
  7.     int i, r1, r2, soma, seq;
  8.     char cpf[11], d1, d2;
  9.  
  10.     while(strlen(cpf) != 11)
  11.     {
  12.         printf("Digite um cpf:\n");
  13.         scanf("%s",cpf);
  14.     }
  15.    
  16.     d1 = cpf[9];
  17.     d2 = cpf[10];
  18.  
  19.     printf("d1 = %c\t d2 = %c\n", d1,d2);
  20.  
  21.     for(i=0;i<10;i++)
  22.     {
  23.         soma += ((int) cpf[i] - '0')*seq;
  24.         seq--;
  25.     }
  26.  
  27.     printf("soma = %d\n",soma);
  28. }
  29.  
  30. int main()
  31. {
  32.     valida();
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement