Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdio.h"
- #include "stdlib.h"
- #include "time.h"
- int main(){
- int tam, aux = 0;
- srand((unsigned) time(NULL));
- printf("Entre com a dimensao: ");
- scanf("%d", &tam);
- int ag[tam];
- printf("\nVetor normal:\n");
- for(int i=0; i<tam; i++){
- ag[i] = rand() % 9+1;
- printf("%d ", ag[i]);
- }
- int cont = 0;
- for(int i=0; i<tam; i++){
- cont = 0;
- for(int j=1; j<=i; j++){
- if(i%j == 0){
- cont++;
- }
- }
- if(cont == 2){
- for(int k=0; k<tam-1; k++){
- for(int l=k; l<tam; l++){
- if(ag[k] > ag[l]){
- aux = ag[k];
- ag[k] = ag[l];
- ag[l] = aux;
- }
- }
- }
- }
- }
- printf("\n\nVetor de primos ordenados:\n");
- for(int i=0; i<tam; i++){
- printf("%d ", ag[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement