Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@seebs
Created March 5, 2018 19:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seebs/1553ec9d1e7449e21e2efae5bd1ea87f to your computer and use it in GitHub Desktop.
Save seebs/1553ec9d1e7449e21e2efae5bd1ea87f to your computer and use it in GitHub Desktop.
/* someone posted to comp.lang.c asking for homework help. i felt the need to contribute.
* -seebs
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <stddef.h>
#include <math.h>
struct {
double lo, close;
int d;
} digits[] = {
{ 6.80183905339058814121, 6.80239476332431092231, '\x39' },
{ 6.68398653227400885157, 6.68461172766792710576, '\x38' },
{ 6.55036579410553621017, 6.55108033504340436792, '\x37' },
{ 6.39609597446756872330, 6.39692965521614631541, '\x36' },
{ 6.21360759808860851905, 6.21460809842219141785, '\x35' },
{ 5.99021376520632919949, 5.99146454710798170851, '\x34' },
{ 5.70211441755550385579, 5.70378247465620091816, '\x33' },
{ 5.29581423632991832307, 5.29831736654803631126, '\x32' },
{ 4.60015764416454686625, 4.60517018598809180219, '\x31' },
{ 9, 9, '\x30' },
{ 4.49423862528080952927, 4.49980967033026502122, '\x39' },
{ 4.37575702166028612794, 4.38202663467388120466, '\x38' },
{ 4.24132675257074609476, 4.24849524204935935501, '\x37' },
{ 4.08597631255158422192, 4.09434456222210041432, '\x36' },
{ 3.90197266957464483639, 3.91202300542814596085, '\x35' },
{ 3.67630067190707610081, 3.68887945411393625150, '\x34' },
{ 3.38439026334577430788, 3.40119738166215546116, '\x33' },
{ 2.97041446556970090143, 2.99573227355399085425, '\x32' },
{ 2.25129179860649530909, 2.30258509299404590109, '\x31' },
{ 9, 9, '\x30' },
{ 2.14006616349627076801, 2.19722457733621956422, '\x39' },
{ 2.01490302054226466666, 2.07944154167983574766, '\x38' },
{ 1.87180217690159134136, 1.94591014905531323187, '\x37' },
{ 1.70474809223842527217, 1.79175946922805495731, '\x36' },
{ 1.50407739677627416697, 1.60943791243410028180, '\x35' },
{ 1.25276296849536805667, 1.38629436111989057245, '\x34' },
{ 0.91629073187415510660, 1.09861228866810978211, '\x33' },
{ 0.40546510810816438486, 0.69314718055994528623, '\x32' },
{ -0.69314718055994528623, 0.00000000000000000000, '\x31' },
{ 9, 9, '\x30' },
{ NAN, NAN, '\x00' }
};
char *names[] = { "first", "second", "third", "oops", "shit", 0 };
int
main(void) {
int n;
double d;
int i;
int hit = 0;
int di = 0;
printf("Enter a Number: ");
fflush(stdout);
if (scanf("%d", &n) != 1) {
fprintf(stderr, "Shyeah right.\n");
exit(EXIT_FAILURE);
}
d = sqrt(n);
if (d != d) {
fprintf(stderr, "Fuck you too buddy.\n");
exit(EXIT_FAILURE);
}
if ((d = log(n)) > 6.9068) {
fprintf(stderr, "Yeah, well, your mama.\n");
exit(EXIT_FAILURE);
}
for (i = (d >= 0 ? 0 : (hit = 1, 20)); digits[i].lo == digits[i].lo; ++i) {
if (d > digits[i].lo) {
printf("The %s digit of the number is %c.\n",
names[di++], digits[i].d);
d = log(exp(d) - exp(digits[i].close));
hit = 2;
}
if (digits[i].lo == 9) {
if (hit == 1) {
printf("The %s digit of the number is %c.\n",
names[di++], digits[i].d);
}
if (hit) {
hit = 1;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment