Providers
Debian Linux
SDF
MinGW-W64
Verizon
Research
Search Engines
Bing
DuckDuckGo
Google
Metacrawler
SearX
Miscellaneous
Faqs and RFCs
Open Directory Project
W3Schools Online Web Tutorials
Wikipedia
Multimedia
CTIS
For the Pigs Among Us
Family Photos
My House
My Photos (1999-2002?)
My Photos (2005)
Retro Computers
Minions of Mirth
Main
Criticals
Criticals (Single Player)
Ghaqua
Maps and Points of Interest
Miscellaneous
Monster Templates
Miscellaneous
Area Codes
Bard’s Tale
Dungeons & Dragons Online
My Blog
Quote of the Day
RogueBasin
Slashdot
The Adventuer’s Guild
Weather
GitHub:eprive/Z80-MBC3
Programming
Main
Across
Biorhythm
BMP Chips
Complex Roots
Magic Square
Magic Square(js)
Matrix(js)
More DOS Programs
Roll
Strip Dups (bash)
Wacky Wood-Worker
How To
Enlightenment 0.16.7.2 Startup Patch
How to Create an OS X Iconset
My RedHat Howto
SSH to VMS (Deathrow OpenVMS Cluster)
Tools
Allowable Mortgage Interest
Dates and Mileage
Day of the Year
Fun With Time
Downloads
Educational
Utilities
circles.c
#include <ctype.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "ncsa.h" #include "query.h" enum ERROR_TYPE {NO_ERROR, DIVISION_BY_ZERO_OR_PARTIAL_FRACTION}; enum ERROR_TYPE error_type = NO_ERROR; void errorMessage(enum ERROR_TYPE); void findAreaAndCircumference(double); char *fractionAndDecimal(double, char *); char buffer[80]; #if !defined(PI) #define PI M_PI #if !defined(M_PI) #undefine PI #define PI 3.14159265 #endif #endif int main(int argc, char **argv) { char query_string[2048]; char length_str[255]; char length_num_str[255]; char length_den_str[255]; char dimension_str[9]; double length = 0; double circumference; double area; double radius; double diameter; int num_exists = 0; int den_exists = 0; setvbuf( stdout, NULL, _IONBF, 0); /* stdout buffering off */ strcpy(query_string, getenv("QUERY_STRING")); get_var(dimension_str, "dimension", query_string); get_var(length_str, "length", query_string); num_exists = get_var(length_num_str, "length_num", query_string); den_exists = get_var(length_den_str, "length_den", query_string); num_exists = (num_exists != EOF) ? num_exists : 0; den_exists = (den_exists != EOF) ? den_exists : 0; if (!num_exists&&!den_exists) { length = atof(length_str); } else { if ((den_exists&&num_exists)&&atof(length_den_str)) length = atof(length_str)+atof(length_num_str)/atof(length_den_str); else error_type = DIVISION_BY_ZERO_OR_PARTIAL_FRACTION; } if (dimension_str[0]=='r') { radius = length; diameter = 2*radius; } else { diameter = length; radius = diameter/2; } if (num_exists||den_exists) { printf("<p>Original input was: %s %s/%s is the %s of the circle.<br>\n", length_str, length_num_str, length_den_str, dimension_str); } else { printf( "<p>Original input was: %s is the %s of the circle.<br>\n", length_str, dimension_str); } printf( "<hr width=\"80%\">\n"); printf( "<p>\n"); if (!error_type) findAreaAndCircumference(radius); else errorMessage(error_type); printf( "<center>" "<img alt=\"[circles]\" src=\"../images/circles2.gif\">" "<p>Enter a length and select whether it is the radius<br>" "or the diameter, and then click on submit.<br>" "<form action=\"circles.pl\" >" "<table class=\"hidden\">" "<td class=\"hidden\"><input type=\"text\" name=\"length\" size=5 > " "<input type=\"text\" name=\"length_num\" size=1 >/" "<input type=\"text\" name=\"length_den\" size=1 ></td>" "<td class=\"hidden\"><table class=\"hidden\">" " <h6><td class=\"hidden\"><input type=\"radio\" name=\"dimension\" value=\"radius\" checked >radius</td><tr>" " <td class=\"hidden\"><input type=\"radio\" name=\"dimension\" value=\"diameter\" >diameter</td></h6>" "</table>" "</td><tr></table>" "<input type=\"submit\" value=\"submit\" >" "<input type=\"reset\">" "</form>" "</center>" ); return 0; } /* main */ void errorMessage(enum ERROR_TYPE error_no) { switch (error_no) { case DIVISION_BY_ZERO_OR_PARTIAL_FRACTION: printf("<h2>\n"); printf("<br>\n"); printf("If any part of the fraction is filled in, you must specify numerator and<br>\n"); printf("denominator. The denominator may not be 0.<br>\n"); printf("</h2>\n"); break; }; } /* errorMessage */ void findAreaAndCircumference(double r) { double circumference; double area; circumference = 2*PI*r; area = PI*r*r; printf("Circles radius is "); fractionAndDecimal(r, buffer); printf(", "); printf("diameter is "); fractionAndDecimal(2*r, buffer); printf("<br>\n"); printf("Area inside the circle is about "); fractionAndDecimal(area, buffer); printf(" square units.<br>\n"); printf("Circumference around the circle is about "); fractionAndDecimal(circumference, buffer); printf(" units.<br>\n"); } /* findAreaAndCircumference */ char *fractionAndDecimal(double x, char *buffer) { double whole; double fractional; char *fractional_str[16] = { " ", " 1/16", " 1/8", " 3/16", " 1/4", " 5/16", " 3/8", " 7/16", " 1/2", " 9/16", " 5/8", " 11/16", " 3/4", " 13/16", " 7/8", " 15/16"}; fractional = modf(x, &whole); printf(" %.0f%s (%.3f) ", whole, fractional_str[(int)(fractional*16)], x); return buffer; } /* fractionAndDecimal */
This source has been viewed 16 times.
Wednesday, 9 July 2025
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org