Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.93 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(){
  4.     int numeroDivisores,contador,primo,n;
  5.     int resto,teste;
  6.    
  7.     scanf("%d",&n);
  8.    
  9.     contador=1;
  10.     primo = 2;
  11.    
  12.    
  13.    
  14.     while(n<=0){
  15.         printf("Fatoracao nao e possivel para o numero %d!\n",n);
  16.         scanf("%d",&n);
  17.     }
  18.         printf("%d = ",n);
  19.         if(n==1){  
  20.             printf("1");
  21.         }else{
  22.             while(n!=1){
  23.                 resto=n%primo;
  24.                     if(resto==0){
  25.                         printf("%d ",primo);
  26.                         n=n/primo;
  27.                         if(n!=1)printf("x ");  
  28.                     }else{
  29.                         resto=n%primo;
  30.                         while(primo<n){
  31.                             primo++;
  32.                            
  33.                             //verificação prima
  34.                             numeroDivisores=0;
  35.                             while(contador<=primo){
  36.                                
  37.                                 teste=primo%contador;
  38.                                 if(teste==0)numeroDivisores++;
  39.                                 contador++;
  40.                                
  41.                             }
  42.                            
  43.                             if(numeroDivisores==2 && n%primo==0){
  44.                                 printf("%d ",primo);
  45.                                 n=n/primo;
  46.                                 if(n!=1)printf("x ");
  47.                            
  48.                             }
  49.                         }
  50.                     }  
  51.             }
  52.         }
  53.    
  54.    
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement