Advertisement
nguyenhappy92

Kiểm tra số hoàn hảo

Oct 14th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. // Kiem tra so hoan hao dung ham con
  2. // khai bao cac ham thu vien chuong trinh
  3. #include<stdio.h>
  4. #include<conio.h>
  5. int kiemtra(int x);
  6. void main()
  7. {
  8. int n;
  9. scanf("%d",&n);
  10. if(kiemtra(n)==1)
  11. {
  12. printf("La so hoan hao");
  13. }
  14. else
  15. {
  16. printf("Khong la so hoan hao");
  17. }
  18. }
  19. int kiemtra(int x)
  20. {
  21. int dem=0;
  22. int m;
  23. m=x;
  24. for(int i=1;i<x;i++)
  25. {
  26. if(x%i==0)
  27. dem=dem+i;
  28. }
  29. if(dem==m)
  30. {
  31. return 1;
  32. }
  33. else
  34. {
  35. return 0;
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement