Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(void){
- int x;
- int y;
- int sum;
- printf("x?");
- scanf("%d", &x);
- if (x == 1){
- printf("Happy Number! :)");
- }
- else if (x==4){
- printf("Unhappy Number! :(");
- }
- else {
- while (sum !=1 && sum !=4){
- sum = 0;
- while (x>0){
- y=x%10;
- sum+=(y*y);
- x/=10;
- }
- x = sum;
- printf("=>%d\n", x);
- }
- }
- if (sum == 1){
- printf("Happy Number! :)");
- }
- else if (sum == 4){
- printf("Unhappy Number! :(");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement