fork download
  1. #include <stdio.h>
  2. #define TAM 3
  3.  
  4. void numeros_perfeitos(int A[]) {
  5. for (int n = 1, cont = 0; cont < TAM; n++) {
  6. int soma = 0;
  7. for (int x = 1; x <= n; x++) {
  8. if (n % x == 0 && x != n) {
  9. soma += x;
  10. }
  11. }
  12. if (soma == n) {
  13. A[cont] = n;
  14. cont++;
  15. }
  16. }
  17. }
  18.  
  19. int main () {
  20. int A[TAM];
  21. numeros_perfeitos(A);
  22. printf("Os primeiros %d números perfeitos são: \n", TAM);
  23. for (int cont = 0; cont < TAM; cont++) {
  24. printf("%d\n", A[cont]);
  25. }
  26. }
Success #stdin #stdout 0s 9432KB
stdin
Standard input is empty
stdout
Os primeiros 3 números perfeitos são: 
6
28
496