|
|
вернуться в форумHelp me please Послано lakme 24 апр 2009 16:57 Here is my code - #include<stdio.h> int main() { __int64 n; int m[100],i=0,j=0;
printf("Enter the number\t"); scanf("%lld",&n);
if(n==1) { j=1; printf("Result is %d\n",j); } else if(n == 0) { j=10; printf("Result is %d\n",j); } else if(n < 10) { j=n; printf("Result is %d\n",j); } else { for(i=9;i>1;i--) { if(n%i == 0) { n=n/i; m[j++]=i; i++; } } if(n!=1) { j=-1; printf("Result is %d\n",j); } else { for(i=j-1;i>=0;i--) printf("%d",m[i]); } }
return 0; } It gives the correct output, i have preformed following test cases -- Input->output 0 -> 10 1 -> 1 2 -> 2 3 -> 3 4 -> 4 5 -> 5 6 -> 6 7 -> 7 8 -> 8 9 -> 9 10 -> 25 11 -> -1 12 -> 26 13 -> -1 14 -> 27 15 -> 35 16 -> 28 17 -> -1 18 -> 29 19 -> -1 20 -> 45 21 -> 37 22 -> -1 23 -> -1 24 -> 38 25 -> 55 26 -> -1 27 -> 39 28 -> 47 29 -> -1 30 -> 56 31 -> -1 32 -> 48 33 -> -1 34 -> -1 35 -> 57 36 -> 49 37 -> -1 38 -> -1 39 -> -1 40 -> 58 41 -> -1 42 -> 67 43 -> -1 44 -> -1 45 -> 59 46 -> -1 47 -> -1 48 -> 68 49 -> 77 50 -> 255 51 -> -1 52 -> -1 53 -> -1 54 -> 69 55 -> -1 56 -> 78 57 -> -1 58 -> -1 59 -> -1 60 -> 256 61 -> -1 62 -> -1 63 -> 79 64 -> 88 65 -> -1 66 -> -1 67 -> -1 68 -> -1 69 -> -1 70 -> 257 71 -> -1 72 -> 89 73 -> -1 74 -> -1 75 -> 355 76 -> -1 77 -> -1 78 -> -1 79 -> -1 80 -> 258 81 -> 99 82 -> -1 83 -> -1 84 -> 267 85 -> -1 86 -> -1 87 -> -1 88 -> -1 89 -> -1 90 -> 259 91 -> -1 92 -> -1 93 -> -1 94 -> -1 95 -> -1 96 -> 268 97 -> -1 98 -> 277 99 -> -1 100 -> 455 still i am getting WA#1, I don't know what the hell is wrong in that. Can any body tell me, why am i getting WA#1?? printf problem if(n==1) { j=1; printf("Result is %d\n",j); } else if(n == 0) { j=10; printf("Result is %d\n",j); } else if(n < 10) { j=n; printf("Result is %d\n",j); if(n!=1) { j=-1; printf("Result is %d\n",j); No need to printf "Result is"! |
|
|