Program stops and the thread appears in the line of sprint:
sprintf(x,"%d",x2);
Isn't this the best way to turn an int (x2) to a string(x)??
int check(int n,char [8]);
int main(){
char x[8]="0";
int N,x2;
scanf("%d",&N);
while(strlen(x)<9){
if(check(N,x)) printf("%s\n",x);
x2=atoi(x);
x2++;
sprintf(x,"%d",x2);
}
return 0;
}
int check(int n,char x[8]){
int l,i,y,count;
l=strlen(x);
y=atoi(x);
count=0;
for(i=0;i<l;i++){
count=count+pow((x[i]-'0'),n);
}
if(count==y) return 1;
else return 0; }
It would be more useful if you'd have posted your compile line + code that actually compiled (i.e. had the correct headers included!). With the move to an array size of 10 this works fine (although takes a while to exit!):
The modified code:
Compile and link:
Debug:
All is good with the world! :D