[Coco] The WinCMOC Project (CoCo C Compiler + Editor)

Melanie and John Mark Mobley johnmarkmelanie at gmail.com
Wed Aug 31 23:00:43 EDT 2016


Perhaps we could run a MobStone Test!

It looks like this:

// Filename: Pi.c
// Description: Compute the value of Pi using the Pythagorean Theorem
// By: John Mark Mobley
// Date: 08-29-2016
// Compile Script: gcc Pi.c
// How to run in Cygwin: ./a.exe
// How to run in Linux: ./a.out

#include <stdio.h>
#include <math.h>

double findDistance(double x1, double y1, double x2, double y2);

int main (int argc, char *argv[])
{
  double x, y, xPrime, yPrime, Pi;
  long long int i;

  printf("Computing the value of Pi...\n");

  Pi=0.0;
  xPrime=0.0;
  yPrime=1.0;  // If x=0.0 then y=1.0

  // This for loop will sweep 30 degrees of a circle
  // First compute the arch length of 30 degrees of a circle
  for (i=0; i<=500000000; i++)
  {
    x=(double) i / 1000000000.0;
    // Find y if the radius of the circle is 1.0
    // Note 1.0 squared is 1.0
    // This is the Pythagorean Theorem
    y=sqrt(1.0-x*x);
    Pi+=findDistance(x, y, xPrime, yPrime);
    xPrime=x;
    yPrime=y;
  }
  // Compute the arch length of 180 degrees
  Pi=Pi*6.0;
  printf("Calculated: %0.14f\n", Pi);
  printf("Memorized.: 3.14159265358979\n");

  return(0);
}

// Find the distance between two points using the Pythagorean Theorem
double findDistance(double x1, double y1, double x2, double y2)
{
  double a, b, c;

  a=fabs(x1-x2);
  b=fabs(y1-y2);
  c=sqrt(a*a+b*b);

  return c;
}

JohnMark ~
$ time ./a
Computing the value of Pi...
Calculated: 3.14159265358351
Memorized.: 3.14159265358979

real    2m20.918s
user    2m19.499s
sys     0m0.062s

JohnMark ~
$

John Mark Mobley




More information about the Coco mailing list