Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- int main (void) {
- int cpf;
- int d1,d2,d3,d4,d5,d6,d7,d8,d9, d10;
- int i, vet[9];
- int sommult[9], sommult2[10];
- int soma1=0, soma2=0;
- int sdv, pdv;
- printf ("Digite o CPF: ");
- scanf ("%d", &cpf);
- d9 = cpf%10;
- d8 = cpf%100;
- d8 = d8*pow(10,(-1));
- d7 = cpf%1000;
- d7 = d7*pow(100,(-1));
- d6 = cpf%10000;
- d6 = d6*pow(1000,(-1));
- d5 = cpf%100000;
- d5 = d5*pow(10000,(-1));
- d4 = cpf%1000000;
- d4 = d4*pow(100000,(-1));
- d3 = cpf%10000000;
- d3 = d3*pow(1000000,(-1));
- d2 = cpf%100000000;
- d2 = d2*pow(10000000,(-1));
- d1 = cpf%1000000000;
- d1 = d1*pow(100000000,(-1));
- vet[0]=d1;
- vet[1]=d2;
- vet[2]=d3;
- vet[3]=d4;
- vet[4]=d5;
- vet[5]=d6;
- vet[6]=d7;
- vet[7]=d8;
- vet[8]=d9;
- for(i=0;i<9;i++) {
- sommult[i]=vet[i]*(i+1);
- soma1+=sommult[i];
- }
- pdv = soma1%11;
- d10 = pdv;
- vet[9]=d10;
- for(i=0;i<=9;i++) {
- sommult[i]=vet[i]*i;
- soma2+=sommult[i];
- }
- sdv = soma2%11;
- printf ("CPF + DV = %d-%d%d", cpf, pdv, sdv);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement