Advertisement
luizaspan

Pefect numbers II

May 12th, 2015
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.35 KB | None | 0 0
  1. // achar os primeiros n números perfeitos
  2.  
  3. #include <stdio.h>
  4.  
  5. int main(void)
  6. {
  7.   int i,n,x,k;
  8.  
  9.   for (n=1;n<100;n++)
  10.     {
  11.       k=0;
  12.       for(i=1;i<n;i++)
  13.     {
  14.       x=(n/i)*i;
  15.  
  16.       if (x==n)
  17.         {
  18.           k+=i; // é divisor
  19.         }
  20.  
  21.     }
  22.  
  23.       if (k==n)
  24.     {
  25.       printf("O número %d é perfeito.\n",n);
  26.     }
  27.  
  28.     }
  29.  
  30.   return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement