Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <windows.h>
- void int_to_bin(int number);
- int main()
- {
- int a=3;
- //int certo=0;
- char nome[50];
- char password[50];
- while(a>0)
- {
- printf("Insira Username:");
- gets(nome);
- if(strcmp(nome,"xpto")==0)
- printf("Username Correto!\n");
- else
- printf("Username Incorreto!\n");
- printf("Insira Password:");
- gets(password);
- if(strcmp(password,"123")==0)
- printf("Password Correta!\n");
- else
- printf("Password Incorreta!\n");
- if(strcmp(nome,"xpto")==0 && strcmp(password,"123")==0)
- {
- printf("Bem vindo\n");
- goto sair;
- }
- else
- a--;
- printf("Restam %d tentativas\n",a);
- }
- if(a==0)
- exit(0);//sair do programa
- printf("Errou");
- sair:
- printf("Entrou no projeto\n");
- //Conversão de números para binário
- do //repetição do programa
- {
- int x;
- //char resp;
- printf("\nIntroduza um numero:\n");
- scanf("%d", &x);
- printf("Em Decimal o numero e: %d \n", x);
- int_to_bin(x);
- printf("\nGostaria de repetir o programa? S/N : ");
- getchar();
- }while(getchar()=='s');
- printf("\n");
- return (0);
- }
- void int_to_bin(int number)
- {
- unsigned int i, step;
- if (0 == number) /* For simplicity's sake, I treat 0 as a special case*/
- {
- printf("0000");
- return;
- }
- i = 1<<(sizeof(number) * 8 - 1);
- step = -1; /* Only print the relevant digits */
- step >>= 4; /* In groups of 4 */
- while (step >= number)
- {
- i >>= 4;
- step >>= 4;
- }
- /* At this point, i is the smallest power of two larger or equal to n */
- while (i > 0)
- {
- if (number & i)
- printf("1");
- else
- printf("0");
- i >>= 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement