## 10591-RunTimeError

Moderator: Board moderators

### 10591-RunTimeError

i don't understand what's wrong. it ran without any problem & the output is also correct.so why RuntimeError

#include<stdio.h>

int main(void)
{

unsigned long a,b,i,c,num[1000],u,sum=0;

scanf("%lu",&c);
for(i=0;i<c;i++) scanf("%ld",&num[i]);

for(i=0;i<c;i++) {
u=num[i];
do{
sum=0;
a=num[i];

b=a%10;
sum=sum+(b*b);
a=a/10;
while(a!=0){

b=a%10;
sum=sum+(b*b);
a=a/10;

}

num[i]=sum;

}while(num[i] / 10 != 0);
if(sum==1) printf("Case #%lu: %lu is a Happy number.\n",i+1,u);
else printf("Case #%lu: %lu is a Unhappy number.\n",i+1,u);
}
return 0;
}
aaa
59557RC
New poster

Posts: 26
Joined: Sun Mar 20, 2005 9:28 pm

### Re: 10591-RunTimeError

59557RC wrote:i don't understand what's wrong. it ran without any problem & the output is also correct.so why RuntimeError

#include<stdio.h>

int main(void)
{

unsigned long a,b,i,c,num[1000],u,sum=0;

scanf("%lu",&c);
for(i=0;i<c;i++) scanf("%ld",&num[i]);

for(i=0;i<c;i++) {
u=num[i];
do{
sum=0;
a=num[i];

b=a%10;
sum=sum+(b*b);
a=a/10;
while(a!=0){

b=a%10;
sum=sum+(b*b);
a=a/10;

}

num[i]=sum;

}while(num[i] / 10 != 0);
if(sum==1) printf("Case #%lu: %lu is a Happy number.\n",i+1,u);
else printf("Case #%lu: %lu is a Unhappy number.\n",i+1,u);
}
return 0;
}

Please post to the appropriate forum and possibly find a thread already open on this problem number.
As for your problem, you assume that you'll get at most 1000 numbers in input. probably this is not the case for Judge's data.
If you fix this ( you don't need to store all the numbers in input first and process it later, just process every number as you read it) you'll get a WA. Check the exact spelling for your answers.

Ciao!!!

Claudio
CDiMa
Experienced poster

Posts: 214
Joined: Fri Oct 17, 2003 5:49 pm
Location: Genova

a number is happy if it ends in 1 after any step of generating the square sum of the digits.
and a number is unhappy if it ends in 4 after any step of generating the square sum of the digits.

this optimisation gets AC
sn23581
New poster

Posts: 2
Joined: Thu Jul 29, 2010 2:02 pm