|  | 
|  | 
| back to board | get answer 669 for n = 4 Hello, my program does this:
 i find the number of numbers with sum S and number of digits n/2, and store it in position SUM[S]
 The total number of solutions is summation of SUM[S]*SUM[S] over all possible S
 
 But I get the answer 669 in this case....where am I wrong?
 
 Here's my code:
 main()
 {
 int N , sums[100] , end , t , t2 , cursum , total = 0;
 scanf("%d" , &N);
 for(t = 0 ; t <= 36 ; t++)
 sums[t] = 0;
 end = pow(10 , N / 2);
 for(t = 0 ; t < end ; t++)
 {
 cursum = 0;
 t2 = t;
 while(t2 > 0)
 {
 cursum += t2 % 10;
 t2 /= 10;
 }
 sums[cursum]++;
 }
 for(t = 0 ; t <= 36 ; t++)
 total += sums[t] * sums[t];
 printf("%d" , total);
 }
Re: get answer 669 for n = 4 for n=4 answer is 670.one more ticket you didn't count is 0000
Re: get answer 669 for n = 4 i have same problem,but i fixed it
 problem is in function pow:
 pow(10,2) returns 99
 ::))) (stupid problem with pow)
 do it with your hands:))
Re: get answer 669 for n = 4 use powl(long, long) from <math.h>
 Edited by author 15.11.2009 01:12
 | 
 | 
|