Advertisement
michael_xgrind

Ex26

Nov 23rd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.77 KB | None | 0 0
  1. #include "stdio.h"
  2. #include "stdlib.h"
  3. #include "time.h"
  4.  
  5. int main(){
  6.     int tam, aux = 0;
  7.    
  8.     srand((unsigned) time(NULL));
  9.    
  10.     printf("Entre com a dimensao: ");
  11.     scanf("%d", &tam);
  12.     int ag[tam];
  13.    
  14.     printf("\nVetor normal:\n");
  15.     for(int i=0; i<tam; i++){
  16.         ag[i] = rand() % 9+1;
  17.         printf("%d ", ag[i]);
  18.     }  
  19.    
  20.     int cont = 0;
  21.     for(int i=0; i<tam; i++){
  22.         cont = 0;
  23.         for(int j=1; j<=i; j++){
  24.             if(i%j == 0){
  25.                 cont++;
  26.             }
  27.         }
  28.        
  29.         if(cont == 2){
  30.            
  31.             for(int k=0; k<tam-1; k++){
  32.                 for(int l=k; l<tam; l++){
  33.                     if(ag[k] > ag[l]){
  34.                         aux = ag[k];
  35.                         ag[k] = ag[l];
  36.                         ag[l] = aux;
  37.                     }
  38.                 }
  39.             }
  40.            
  41.         }
  42.     }
  43.    
  44.     printf("\n\nVetor de primos ordenados:\n");
  45.     for(int i=0; i<tam; i++){
  46.         printf("%d ", ag[i]);
  47.     }
  48.    
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement