delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/10/22/03:40:28

From: "Mark Tsui" <tsui AT netspace DOT net DOT au>
Newsgroups: comp.os.msdos.djgpp
Subject: Pi
Date: Thu, 22 Oct 1998 18:30:09 +1000
Organization: A customer of Netspace Internet
Lines: 57
Message-ID: <70mqm1$st1$1@otis.netspace.net.au>
NNTP-Posting-Host: dialup-m1-46.sydney.netspace.net.au
X-Trace: otis.netspace.net.au 909045249 29601 210.15.248.46 (22 Oct 1998 08:34:09 GMT)
X-Complaints-To: abuse AT netspace DOT net DOT au
NNTP-Posting-Date: 22 Oct 1998 08:34:09 GMT
X-Newsreader: Microsoft Outlook Express 4.72.3110.1
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

This is a program I tried to write for pi.

for some reason, the program seem to display very poor accuracy. about 5-6
decimal points.

also, is there a way to clear the screen instead of \n?

and I cannot make breakpoints in my program. I suspect that it is not
compiled with the -g switch, but I made sure that it is, and I still can't
get the break points to work

any help will be appreciated. Thanks


#include <math.h>
#include <iostream.h>
#include <conio.h>


main()
{
 int accuracy, counter;
 long double a, b, la, lb;

 for(counter=0; counter <40 ; counter++) cout << "\n";

 gotoxy(1,1);
 cout << "Enter accuracy numter: ";
 cin >> accuracy;

 la = 2 * sqrt(3);
 lb = 3;

 for (counter=0 ; counter < accuracy ; counter++)
 {
  a = (2 * la * lb)/ (la + lb);
  b = sqrt((a * lb));


  la = a;
  lb = b;

  gotoxy(1,2);

  cout << "Pi is less than " << a << "\n";
  cout << "Pi is more than " << b << "\n";
  cout << "Pi is about " << (a + b) / 2 << "\n";


 }
  getch();
  return 0;

 }



- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019