Providers
Debian Linux
SDF
MinGW-W64
Verizon
Research
Faqs and RFCs
FileSearching
Google
Google Groups
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
roots.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); */ typedef struct s_tag { struct s_tag *pt; float a; float b; float theta; float r; } COMPLEX_T; int main ( int argc, char **argv ) { char query_string[2048]; char root_str[255]; char real_str[255]; char imaginary_str[255]; int n, i; double pi; double a, b, r, theta, dtheta; COMPLEX_T *ptr, *root, blank; /* initialization */ pi = acos(-1); /* input */ setvbuf( stdout, NULL, _IONBF, 0); /* stdout buffering off */ strcpy(query_string, getenv("QUERY_STRING")); get_var(root_str, "root", query_string); get_var(real_str, "real", query_string); get_var(imaginary_str, "imaginary", query_string); n = atoi(root_str); a = atof(real_str); b = atof(imaginary_str); if (!n) n=2; /* if root is blank assume square root */ /* computations */ r = sqrt(a*a + b*b); /* Use arcsine as indicated in image and fix the sign of theta. MJC 10/30/24 */ theta = asin(b/r)*(a<0?-1:1); dtheta = 2 * pi/n; root = malloc(sizeof blank); ptr = root; ptr->pt = NULL; ptr->theta = theta/n; ptr->r = exp(log(r)/n); ptr->a = ptr->r * cos (ptr->theta); ptr->b = ptr->r * sin (ptr->theta); for (i=1; i<n; i++) { ptr->pt = malloc(sizeof blank); ptr = ptr->pt; ptr->r = root->r; ptr->theta = root->theta + i*dtheta; ptr->a = ptr->r * cos (ptr->theta); ptr->b = ptr->r * sin (ptr->theta); ptr->pt = NULL; } /* output */ printf( "<p><center>" "<h1>Roots of complex numbers." "</h1></center>\n"); printf("\n<hr><p>"); printf("\n|%lf%+lfi| = ",a,b); printf("%lf.", r); printf("\n<br>θ = %lf radians (%lf°).", theta, theta*180/pi); printf("\n<br>∆ = %lf radians (%lf°).", dtheta, dtheta*180/pi); printf("\n</p><p>"); switch (n) { case 2: printf("\n<h1>√<span style=\"text-decoration:overline\">%lf%+lfi</span> =</h1>",a,b); break; default: printf("\n<h1><sup>%d</sup>√<span style=\"text-decoration:overline\">%lf%+lfi</span> =</h1>",n,a,b); break; } /* switch */ ptr = root; printf("\n<ul>"); do { printf("\n<li>%.5lf%+.5lfi</li>", 0.0000005+ptr->a, 0.0000005+ptr->b); ptr = ptr->pt; } while (ptr); printf("</ul><hr>"); printf( "<img alt=\"[circles]\" src=\"../images/circles3.gif\">" "<p>Enter the root you wish to find of a complex number, followed by the<br>" "real and imaginary components of the complex number.<br>" "</h2>" "<hr>" "<form action=\"../cgi-bin/roots.pl\" >" "<table class=\"hidden\">" "<td class=\"hidden\"><sup><input type=\"text\" name=\"root\" size=1 ></sup>√ " "<input type=\"text\" name=\"real\" size=4 >+" "<input type=\"text\" name=\"imaginary\" size=4 >i" "</td>" "</table>" "</td><tr></table>" "<input type=\"submit\" value=\"submit\" >" "<input type=\"reset\">" "</form></center>" ); /* clean up */ ptr = root; while (ptr) { root = ptr->pt; free(ptr); ptr = root; } return 0; }
This source has been viewed 19 times.
Friday, 6 December 2024
Michael J. Chappell
Contact me at:
mcsuper5@freeshell.org