FORUM DARKERS

Tecnologia & Informática => Programação => C/C#/C++ => Topic started by: nizep on 08 de June , 2007, 09:04:38 PM

Title: [source] verificador de cpf
Post by: nizep on 08 de June , 2007, 09:04:38 PM
meu 2. programa em C

verificador de cpf

queria agradecer ao Dark_Side que tiro uma duvida ke tava foda

#include <stdio.h>
#include <string.h>
#include <windows.h>
               
main() {
       
char cpf[11];
int d1=0, d2=0, i, aux;

printf("Digite o cpf <somente numeros> : ");
gets (cpf);
for (i=0; i<=8; i++) {
    aux = cpf[i] - 48;
    d1 = (aux*(i+1))+d1;
}
d1 = d1%11;
if (d1>=10){
   d1=0;
}
aux = cpf[9]-48;     
if (d1==aux) {
    for (i=1; i<=9; i++) {
        aux = cpf[i] - 48;
        d2 = (aux*i)+d2;
    }                   
    d2 = d2%11;
    if (d2>=10){
       d2=0;
    }
    aux = cpf[10]-48;   
    if (d2==aux)
       printf("CPF VALIDO!\n");
    else
        printf("CPF INVALIDO!\n");       
}       
else
    printf("CPF INVALIDO!\n"); 
system ("Pause");           
}   

Title: Re: [source] verificador de cpf
Post by: l u b c k e on 09 de June , 2007, 09:36:34 AM
Parabéns nizep, é bom ver mais pessoas intereçando-se pela programação. Continue assim...


Até mais...
Title: Re: [source] verificador de cpf
Post by: Anonymous on 09 de June , 2007, 09:59:51 AM
Realmente o programa esta muito bom !!!! ;D

Pra ninguem falar algo de "Nâo funciona, não sei como compilar e talz..." ai segue o print.

(//http://img167.imageshack.us/img167/7530/imagemae5.jpg)
Title: Re: [source] verificador de cpf
Post by: nizep on 10 de June , 2007, 09:32:52 PM
valew galera

dei uma melhorada no programa

agora com estrutura de repetiçao e chamando uma funçao

#include <stdio.h>
#include <string.h>
#include <windows.h>

int verifica_cpf (char cpf[11]) {
   
int d1=0, d2=0, i, aux;   

for (i=0; i<=8; i++) {
    aux = cpf[i] - 48;
    d1 = (aux*(i+1))+d1;
}
d1 = d1%11;
if (d1>=10){
   d1=0;
}
aux = cpf[9]-48;     
if (d1==aux) {
    for (i=1; i<=9; i++) {
        aux = cpf[i] - 48;
        d2 = (aux*i)+d2;
    }                   
    d2 = d2%11;
    if (d2>=10){
       d2=0;
    }
    aux = cpf[10]-48;   
    if (d2==aux)
       return 1;
    else
        return 0;
}       
else
    return 0;
}   
               
main() {
       
char cpf[11];

while (true) {
      printf("Digite o cpf <somente numeros>\nOu <s> para sair: ");
      gets (cpf);
      if (cpf[0]==115)
         break;
      if (verifica_cpf(cpf)==true)
         printf("CPF VALIDO\n\n");
      else
          printf ("CPF INVALIDO\n\n");             
}
}   

Title: Re: [source] verificador de cpf
Post by: _Dr4k0_ on 11 de June , 2007, 05:58:43 PM
hmm o algoritmo esta bem feito, legal


mais só uns conselhos tente evitar libs a toa.. a windows.h e a string.h, pela lida rapida que li não vi necessidade nenhuma delas..ou seja tente não usar, que vai diminuir o tamanho do code compilado..que pode ser útil em vários casos..
Title: Re: [source] verificador de cpf
Post by: nizep on 12 de June , 2007, 01:16:01 AM
valew _Dr4k0_

a windows.h eu eskeci de tira ke eu reaproveitei o outro codigo ke usava ela

mas a string.h precisa por causa do char cpf 

ou nao?!