FresHHerB

Printas primos

Sep 20th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.89 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <malloc.h>
  4.  
  5. /*int resto_divisao (int dividendo, int divisor){
  6.  
  7.     int resto;
  8.  
  9.     resto=dividendo%divisor;
  10.     return(resto);
  11. }*/
  12.  
  13. void main(){
  14.  
  15.     int numero=4;
  16.     int vet[numero];
  17.     int vet_primo[numero];
  18.     int i,j,x=0,cont=0,cont2=0,aux;
  19.     int *pont;
  20.    
  21.     for(i=2;i<=numero;i++){ //atribuir valor de 2 ate n aos vetores
  22.         vet[i-2]=i;
  23.     }
  24.    
  25.     for (i=2;i<numero+1;i++){
  26.         printf("\nO valor do vetor %d eh %d\n", i-1, vet[i-2]);
  27.     }
  28.  
  29.     for(i=numero-1;i>=0;i--){ //i=3 NUMERO 4
  30.         for(j=numero-2;i>=0;j--){ //j=2 numero 3
  31.             if((vet[i])%(vet[j])==0){
  32.                 cont=cont++;
  33.             }
  34.         }
  35.         if(cont==0){
  36.             vet_primo[x]=vet[numero-1];
  37.             x++;
  38.             cont2++;
  39.         }
  40.     }
  41.    
  42.     printf("\nOs numeros primos sao: \n");
  43. }
Advertisement
Add Comment
Please, Sign In to add comment