TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Bill Birrell
from: Jasen Betts
date: 2004-04-13 07:54:06
subject: Squares

Hi Bill.

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 - 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> }

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

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

 -=> Bye <=-

---
* Origin: Darth Vader sleeps with a Teddywookie. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 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™.