Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int sum(int x)
- {
- return x%10+x/10;
- }
- int happy(int x)
- {
- int p,q;
- p=x/1000;
- q=x/100%10;
- if (sum(p)!=q) return 0;
- p=x%100;
- return sum(p)==q;
- }
- int main()
- {
- int i;
- for (i=0; i<=99999; ++i)
- if (happy(i)) printf("%05d ",i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement