Created
April 30, 2015 02:22
-
-
Save shohan4556/ee729c3b43b60904dfd7 to your computer and use it in GitHub Desktop.
uva 10591 happy number solution in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Author :Shohanur Rahaman | |
/// UVA 10591 | |
#include<stdio.h> | |
#include<math.h> | |
int main() | |
{ | |
int n,sum,a,tc,ca,b; | |
while(scanf("%d",&tc)==1){ | |
for(ca=1;ca<=tc;ca++){ | |
scanf("%d",&n); | |
a=n; | |
sum=0; | |
while(n<9 || n>9){ | |
if(n<=9){ | |
sum=n; | |
break; | |
} | |
while(n!=0){ | |
b=n%10; | |
sum=sum+(b*b); | |
n=n/10; | |
} | |
n=sum; | |
sum=0; | |
} | |
if(sum==1 || sum==7) | |
printf("Case #%d: %d is a Happy number.\n",ca,a); | |
else | |
printf("Case #%d: %d is an Unhappy number.\n",ca,a); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment