Advertisement
Guest User

Untitled

a guest
Jul 6th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <windows.h>
  4.  
  5. void int_to_bin(int number);
  6.  
  7. int main()
  8. {
  9.  
  10. int a=3;
  11. //int certo=0;
  12. char nome[50];
  13. char password[50];
  14. while(a>0)
  15. {
  16.  
  17. printf("Insira Username:");
  18.  
  19. gets(nome);
  20.  
  21. if(strcmp(nome,"xpto")==0)
  22. printf("Username Correto!\n");
  23. else
  24. printf("Username Incorreto!\n");
  25.  
  26. printf("Insira Password:");
  27.  
  28. gets(password);
  29.  
  30. if(strcmp(password,"123")==0)
  31. printf("Password Correta!\n");
  32. else
  33. printf("Password Incorreta!\n");
  34.  
  35.  
  36. if(strcmp(nome,"xpto")==0 && strcmp(password,"123")==0)
  37. {
  38. printf("Bem vindo\n");
  39. goto sair;
  40. }
  41. else
  42.  
  43.  
  44. a--;
  45. printf("Restam %d tentativas\n",a);
  46. }
  47. if(a==0)
  48. exit(0);//sair do programa
  49.  
  50. printf("Errou");
  51.  
  52. sair:
  53. printf("Entrou no projeto\n");
  54.  
  55. //Conversão de números para binário
  56.  
  57. do //repetição do programa
  58. {
  59. int x;
  60. //char resp;
  61.  
  62. printf("\nIntroduza um numero:\n");
  63. scanf("%d", &x);
  64.  
  65. printf("Em Decimal o numero e: %d \n", x);
  66.  
  67. int_to_bin(x);
  68.  
  69. printf("\nGostaria de repetir o programa? S/N : ");
  70. getchar();
  71.  
  72. }while(getchar()=='s');
  73. printf("\n");
  74.  
  75. return (0);
  76. }
  77.  
  78.  
  79.  
  80. void int_to_bin(int number)
  81. {
  82. unsigned int i, step;
  83.  
  84. if (0 == number) /* For simplicity's sake, I treat 0 as a special case*/
  85. {
  86. printf("0000");
  87. return;
  88. }
  89.  
  90. i = 1<<(sizeof(number) * 8 - 1);
  91.  
  92. step = -1; /* Only print the relevant digits */
  93. step >>= 4; /* In groups of 4 */
  94. while (step >= number)
  95. {
  96. i >>= 4;
  97. step >>= 4;
  98. }
  99.  
  100. /* At this point, i is the smallest power of two larger or equal to n */
  101. while (i > 0)
  102. {
  103. if (number & i)
  104. printf("1");
  105. else
  106. printf("0");
  107. i >>= 1;
  108. }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement