Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int sum(int x)
  4. {
  5. return x%10+x/10;
  6. }
  7.  
  8. int happy(int x)
  9. {
  10. int p,q;
  11. p=x/1000;
  12. q=x/100%10;
  13. if (sum(p)!=q) return 0;
  14. p=x%100;
  15. return sum(p)==q;
  16. }
  17.  
  18. int main()
  19. {
  20. int i;
  21. for (i=0; i<=99999; ++i)
  22. if (happy(i)) printf("%05d ",i);
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement