Advertisement
Willian_ramalho

MEga sena

Jun 24th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.33 KB | None | 0 0
  1. //sorteio da mega sena
  2. #include <iostream>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. using namespace std;
  6.  
  7.  
  8.  
  9. bool Existe(int valores[], int tam, int valor){
  10. for(int i = 0;i<tam;i++){
  11.  
  12. if(valores[i]==valor)
  13. return true;
  14.  
  15. }
  16. return false;
  17. }
  18.  
  19. void GerarAleatorios(int numeros[], int quantNumeros, int Limite){
  20. srand(time(NULL));
  21.  
  22.  
  23. int v;
  24. for(int i=0;i<quantNumeros;i++){
  25.  
  26. v = rand() % Limite;
  27. if(!Existe(numeros,i,v))
  28. numeros[i] = v;
  29.  
  30. numeros[1] = rand() % Limite;
  31. }  
  32.  
  33. }
  34.  
  35. int main()
  36. {printf("\n\to numero da mega sena eh:\n\t");
  37.  
  38. int numeros[6];
  39. GerarAleatorios(numeros,6,59);
  40. for(int i= 0; i<6; i++){
  41. cout<<numeros[i]<<"-";
  42. }
  43.  
  44.  
  45. '-----------------------''-----------------------''-----------------------''-----------------------''-----------------------'
  46.  
  47. //arquivo txt, pra fazer a aposta
  48. #include <stdio.h>
  49. #include <stdlib.h>
  50. int main(void)
  51. {
  52.   FILE *pont_arq;
  53.   char palavra[1000];  
  54.  
  55.  
  56.   pont_arq = fopen("C:\\Users\\willian\\Videos\\jogadas.txt", "w");
  57.  
  58.  
  59.   if(pont_arq == NULL)
  60.   {
  61.   printf("Erro na abertura do arquivo!");
  62.   return 1;
  63.   }
  64.  
  65.   printf("Escreva uma palavra para testar gravacao de arquivo: ");
  66.   scanf("%s", palavra);
  67.  
  68.  
  69.   fprintf(pont_arq, "%s", palavra);
  70.  
  71.  
  72.   fclose(pont_arq);
  73.  
  74.   printf("Dados gravados com sucesso!");
  75.  
  76.  
  77.   return(0);
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement