circle.c
that does the following:
The formula for determining the length lAB of the line between points (xA, yA) and (xB, yB) is
_________________ | |
√ | (xA -xB)2+(yA -yB)2 |
The pow() function can be used for exponentiation. pow(x, y)
computes x
to the y
power. There are some subtleties
involved in using pow(), so an alternative way to square a number would be
to simply multiply the number by itself. Either way is acceptable for this
homework problem.
Note: When compiling a program that uses a function, such as sqrt()
or pow(),
from the math library, the compilation command needs to include the option
-lm
. For example:
gcc -Wall -lm circle.c
#define
to define the
value of pi as 3.14159.
Do not
use loops, conditionals, arrays, user-defined functions (other than main) or any other constructs/statements
that haven't yet been covered in class.
Enter the x-coordinate of Point A: -3.2 Enter the y-coordinate of Point A: 2 Enter the x-coordinate of Point B: 1.115e+2 Enter the y-coordinate of Point B: 6.7 Length of radius is 114.796249 Circumference is 721.285522 Area is 41400.433594
circle.c
program. In one version,
all of the variables declared in the program were of type float.
In the other version, all of the variables were of type double. When
I run the two programs with the same inputs, they sometimes produce different
outputs. For example, I ran both versions with endpoints (0,0) and (5,0) for
the radius (i.e. the length of the radius was 5.0). The float
version of the program calculated the circumference of the circle to be
31.415899. The double version of the program calculated the circumference to be 31.415900.
Read these Wikipedia entries on
single-precision floating point format and
double-precision floating point format. In your own words, explain why
the two versions of my program gave me different answers for the circumference.
Your explanation will be submitted as part of your README.TXT
file (see next section, Deliverables).
README.TXT
that contains information about the installation and operating instructions
for the software, known bugs, credits and acknowledgements, and other information.
Write a short README.TXT
file that summarizes your program, how to run it,
and details any assumptions you made, if any (other than the assumption listed above) or problems you had. Also include in your README.TXT file your
explanation of the differences between float and double.
You can use kwrite to create
your README.TXT
file.
Make sure both your C source code file and your README.TXT file contain the name(s) and WPI username(s) of the author(s) of the files.
Submit your C source code file and your README.TXT
file to
web-based turnin no later
than 5pm on March 19. The name of the turnin project is Homework 1.
Programs submitted after 5pm on March 19 will be tagged as late,
and will be subject to the late homework
policy.