Advertisement
caiofersousa

Gerar inteiros randomicos nao repetidos c++

Nov 6th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1.     #include <iostream>
  2.     #include <stdlib.h>
  3.     #include <stdio.h>
  4.     //#include<conio.h>
  5.     #include <time.h>
  6.     using namespace std;
  7.    
  8.     int main() {
  9.    
  10.         int i = 0, j = 0, k = 0 ,va[10], vb[10], aux = 0;
  11.    
  12.             srand(time(NULL));
  13.             for(i = 1; i <=10; i++)
  14.             {
  15.                 va[i] = 1 + rand() % 20;
  16.                 for(j = 1; j<i;j++)
  17.                 {
  18.                     if(va[i] == va[j])
  19.                     {
  20.                            
  21.                         i--;
  22.                    
  23.                        
  24.                        
  25.                     }
  26.                
  27.    
  28.                
  29.                    
  30.                 }
  31.                    
  32.                
  33.                
  34.             }
  35.             for(int i = 1; i <=10;i++)
  36.                 printf("\n%i",va[i],"\n");
  37.    
  38.         printf("\nVETOR");
  39.        
  40.    
  41.    
  42.    
  43.    
  44.    
  45.         return 0;
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement