View Single Post
Join Date: Oct 2005
Posts: 2
Reputation: bigwillis234 is an unknown quantity at this point 
Solved Threads: 0
bigwillis234's Avatar
bigwillis234 bigwillis234 is offline Offline
Newbie Poster

Re: homework assignment help

 
0
  #5
Oct 27th, 2005
this is what i got now. it still takes a long time. like an hour



int n, d=1, n2, d2;
double pie= 3.141592643563118, guess, piguess = 3.15;

int main()
{

while(d <= 1000000) { /* d goes to 1000000 */
n=3.1*d; /* started n at 3.1 * to get right to pi area*/
while(n <= 3.2*d ){ /*shortened loop for values */


guess = fabs(((double)n/d) - pie); /*abs value to compare guess*/
if( guess < piguess ){
n2= n;
d2= d;
piguess= guess;

}n++;
}d++;
}

printf( "%d / %d", n2, d2);
Reply With Quote