|
|
вернуться в форумWhat's wrong with this code?? #include <stdio.h> unsigned long N; int ind; char buf[51]; int main() { int i,n; scanf("%lu",&N); if (N<10) { if (N!=0) printf("%lu\n",N); else printf("1\n"); return 0; } buf[49]=0; ind=48; for (;;) { n=1; for (i=9;i>=2;i--) if (N%i==0) { n=0;N/=i;buf[ind--]=i+'0';break; } if (N==1) break; if (n) { printf("1\n"); return 0; } } printf("%s\n",buf+ind+1); return 0; } Re: What's wrong with this code?? > if (N<10) { > if (N!=0) printf("%lu\n",N); > else printf("1\n"); > return 0; > } if(N==0) printf("10\n"); 1!=0 but 1*0=0; Thanks, but it produces a wrong answer again Re: Thanks, but it produces a wrong answer again Check if number>9; 22=2*11 where 11>9 and you must print -1 39=3*13 -> -1 A fool mistake!!! I thought that if it's not possible u must print 1, now I saw that it's -1. Yeah, this task contains some good traps, is't it ? :) :)))) |
|
|