TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Jasen Betts
from: Roy J. Tellason
date: 2004-04-14 20:07:04
subject: Squares

Jasen Betts wrote in a message to Bill Birrell:

 JB> Hi Bill.

 JB> 11-Apr-04 13:05:00, Bill Birrell wrote to Neil Heller


 >> Wouldn't you rather write:

 >> for (n = 0; n < sqrt(INT_MAX); n++)

 >> Otherwise, you would start getting negative numbers
 >> after a bit.

 BB>     Fair enough, but I would rather not evaluate sqrt(INT_MAX) each time
 BB> through the loop, so for the price of one more stacked identifier
 BB> - const
 BB> int
 BB> top:

 BB> #include
 BB> #include
 BB> int main(void)
 BB> {   int n;
 BB>     const int top=(int)sqrt(INT_MAX);
 BB>     for(n = 0; n      return 0;
 BB> }

 JB> if speed is a issue, don't multiply either :)

 JB>  #include 
 JB>  #include 
 JB>  #include 
 JB>  int main(void)
 JB>  {   int n,s;
 JB>      const int top=(int)sqrt(INT_MAX)*2;
 JB>      for(n = -1,s=1; n < top; n+=2) printf("%d %d %d
\n",s+=n,n*n,
 JB> top);      return 0;
 JB>  }

I don't see how speed *can* be an issue,  this code is I/O-bound...

--- 
* Origin: TANSTAAFL BBS 717-838-8539 (1:270/615)
SEEN-BY: 633/267 270
@PATH: 270/615 150/220 3613/1275 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.