Advertisement
FelipeNeto2

Números perfeitos (C)

Jul 29th, 2019
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4.   int n, i, c , soma , j;  
  5.  
  6.   printf("Digite: ");
  7.   scanf("%d", &n);
  8.  
  9.   int v[n];
  10.  
  11.   for(j=4; j<=n; j++){
  12.     c=0, soma = 0;
  13.     for(i=1; i<j; i++){
  14.       if(j%i==0){      
  15.         v[c] = i;
  16.         c++;
  17.       }
  18.     }
  19.  
  20.     for(i=0; i<c; i++){
  21.       soma+=v[i];
  22.     }
  23.        
  24.     if(soma==j){
  25.       printf(" %d", j);
  26.     }
  27.   }
  28.  
  29.   return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement