Paisen

rand_primos

Sep 27th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. /* 6) Dado un número n, rellene aleatoriamente
  2. el arreglo (Bn), posteriormente, buscarlos elementos
  3.  de Bn que son primos y mostrarlos en pantalla.*/
  4.  
  5. #include<stdio.h>
  6. #include<stdlib.h>
  7. #include<time.h>
  8.  
  9. int V[50],i,x,z=1,cont,y;
  10.  
  11. int main (){
  12.     printf("Tamano de tu arreglo\n");
  13.     scanf("%i",&x);
  14.    
  15.     srand(time(NULL));
  16.     for(i=0; i<x; i++){
  17.         V[i]=rand();
  18.        
  19.         printf("%d\n",V[i]);
  20.     }
  21.    
  22.     for(i=0; i<x; i++){
  23.     while(z<=V[i]){
  24.     z++;
  25.     if(V[i]%z==0){
  26.         cont++;
  27.         }  
  28.     if(cont<2){
  29.         y=i;
  30.     printf("EL es primo %d\n",V[y]);
  31.     break;
  32.     }
  33. }
  34. }
  35.     printf("\n\n");
  36.     system("pause");
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment