| View previous topic :: View next topic |
| Author |
Message |
dirbax Member
Joined: 28 Feb 2009 Posts: 10
|
|
| Back to top |
|
 |
aswoods S.O.S. Oldtimer

Joined: 23 Feb 2009 Posts: 289 Location: Adelaide, Australia
|
Posted: Sat, 7 Mar 2009 00:21:56 UTC Post subject: |
|
|
Your C code will only work for a tiny range of values, and I would replace "pow" with r*r*r |
|
| Back to top |
|
 |
dirbax Member
Joined: 28 Feb 2009 Posts: 10
|
Posted: Sat, 7 Mar 2009 14:48:35 UTC Post subject: |
|
|
| Thanks astwoods , would you mind to explain me how did you find it ? |
|
| Back to top |
|
 |
dirbax Member
Joined: 28 Feb 2009 Posts: 10
|
Posted: Sat, 7 Mar 2009 16:25:15 UTC Post subject: |
|
|
What about this function
int F( int n , int a, int b )
{
int r=0;
int mid=(a+b)/2;
for( int i=0 ; i<n ; i+=2, mid++)
{
if( i<mid ) r++ ;
if( i<mid && i>a ) r-- ;
if( i==mid ) r=r/2 ;
if( i>mid || i<b ) r=sqrt(r) ;
}
return r ;
} |
|
| Back to top |
|
 |
laracroft S.O.S. Newbie
Joined: 03 Nov 2009 Posts: 3
|
Posted: Wed, 4 Nov 2009 05:51:57 UTC Post subject: |
|
|
Hi Dirbax,
Me Laracroft,
I read your post and found no incompatibility converting code to math.
Only change you should do is change the type of variable int r to long r.
Stay connected. _________________ usb flash drive |
|
| Back to top |
|
 |
|