Skip to content

Commit

Permalink
daily update 5.15
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed May 15, 2024
1 parent 0cd0179 commit eff3ed5
Show file tree
Hide file tree
Showing 189 changed files with 9,068 additions and 67 deletions.
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions 14/14.18.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//函数指针使用方式;

#include <stdio.h>
#define ASD struct c \
{ \
Expand Down
2 changes: 1 addition & 1 deletion 15/15.9_10.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../s_gets.h"
#include "../s_gets1.h"
#include <limits.h>

int b2dcov (const char * pbin)
Expand Down
10 changes: 10 additions & 0 deletions 16/16.1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <stdio.h>
int main (void)
{
int/**/fh/**/;

fh = 7;
printf ("%d\n", fh);

return/**/0;
}
18 changes: 18 additions & 0 deletions 16/16.10.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#if __STDC_VERSION__ != 201112L
#error Not C11

#endif
#include <stdio.h>

#line 10 "egvev.c"

int main (void)
{
printf ("This is line %d. \n", __LINE__);
printf ("The file is %s. \n", __FILE__);
#line 80 "eev.c"
printf ("This is line %d. \n", __LINE__);
printf ("The file is %s. \n", __FILE__);

return 0;
}
Binary file added 16/16.10.exe
Binary file not shown.
12 changes: 12 additions & 0 deletions 16/16.11.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <stdio.h>

#define PRAGMA(X) _Pragma (#X)
#define LIMRG(X) PRAGMA (STDC CX_LIMITED_RANGE X)

int main (void)
{
LIMRG (ON)
printf ("Hello World from LIMRG(ON)\n");

return 0;
}
21 changes: 21 additions & 0 deletions 16/16.12.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <stdio.h>

#define MYTYPE(X) _Generic \
((X), \
int: "int", \
float: "float", \
double: "double", \
default: "other" \
)

int main (void)
{
int d = 5;

printf ("%s\n", MYTYPE (d));
printf ("%s\n", MYTYPE (2.0 * d));
printf ("%s\n", MYTYPE (3L));
printf ("%s\n", MYTYPE (&d));

return 0;
}
18 changes: 18 additions & 0 deletions 16/16.13.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>

inline static void eatline (void)
{
while (getchar() != '\n');
}

int main (void)
{
char str[30];

printf ("test: \n");
scanf ("%s", str);
eatline ();
printf ("%s\n", str);

return 0;
}
53 changes: 53 additions & 0 deletions 16/16.14.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <stdio.h>
#include <math.h>

#define RAD_TO_DEG (180 / (4 * atan (1)))

typedef struct polar_v
{
double magnitube;
double angle;
} Polar_v;

typedef struct rect_v
{
double x;
double y;
} Rect_v;

Polar_v rect_to_polar (Rect_v);

int main (void)
{
Rect_v input;
Polar_v result;

puts ("Enter x and y coordinates; enter q to quit: ");

while (scanf ("%lf %lf", &input.x, &input.y) == 2)
{
result = rect_to_polar (input);
printf ("magnitude = %0.2f, angle = %0.2f. \n", result.magnitube, result.angle);
}

printf ("Thank you for using. \n");

return 0;
}

Polar_v rect_to_polar (Rect_v rv)
{
Polar_v pv;

pv.magnitube = sqrt (rv.x * rv.x + rv.y * rv.y);

if (!pv.magnitube)
{
pv.angle = 0.0;
}else
{
pv.angle = RAD_TO_DEG * atan2 (rv.y, rv.x);
}

return pv;
}
31 changes: 31 additions & 0 deletions 16/16.15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <stdio.h>
#include <math.h>

#define RAD_TO_DEG (180 / (4 * atan (1)))

//以下代码和课本上等价;
#define SQRT(X) _Generic ((X), long double: sqrtl (X), default: sqrt (X), float: sqrtf (X))
#define SIN(X) _Generic ((X), long double: sinl, default: sin, float: sinf) ((X) / RAD_TO_DEG)

int main (void)
{
float x = 45.0f;
double xx = 45.0;
long double xxx = 45.0L;

long double y = SQRT (x);
long double yy = SQRT (xx);
long double yyy = SQRT (xxx);

printf ("%.17Lf\n", y);
printf ("%.17Lf\n", yy);
printf ("%.17Lf\n", yyy);

int i = 45;
yy = SQRT (i);
printf ("%.17Lf\n", yy);
yyy = SIN (xxx);
printf ("%.17Lf\n", yyy);

return 0;
}
36 changes: 36 additions & 0 deletions 16/16.16.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
void sign_off (void);
void too_bad (void);

int main (void)
{
int n;

atexit (sign_off);
printf ("Enter an integer: \n");

if (scanf ("%d", &n))
{
printf ("%d is %s. \n", n, (n % 2) ? "odd" : "even");
}else
{
puts ("That's no integer.");
atexit (too_bad);
exit (EXIT_FAILURE);
}

return 0;
}

void sign_off (void)
{
printf ("Thus terminates another magnificent program from ");
printf ("SeeSaw Software. \n");
}

void too_bad (void)
{
printf ("SeeSaw Software extends its heartfelt condolences ");
printf ("to you upon the failure of your program. \n");
}
18 changes: 18 additions & 0 deletions 16/16.17.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "16.17_18.h"

int main (void)
{
srand ((unsigned int) time (0));
double vals[NUM];

fill_array (vals, NUM);

printf ("Random list: \n");
show_array (vals, NUM);

printf ("\nSorted list: \n");
qsort (vals, NUM, sizeof (double), my_comp);
show_array (vals, NUM);

return 0;
}
15 changes: 15 additions & 0 deletions 16/16.17_18.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifndef _16_17_18_H
#define _16_17_18_H


#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define NUM 40

void fill_array (double ar[], int n);
void show_array (const double ar[], int n);
int my_comp (const void * p1, const void * p2);

#endif
34 changes: 34 additions & 0 deletions 16/16.18.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "16.17_18.h"

void fill_array (double ar[], int n)
{
for (int index = 0; index < n; index ++)
{
ar[index] = ((double) rand ()) / ((double) rand () - 0.1);
}
}

void show_array (const double ar[], int n)
{
for (int index = 0; index < n; index ++)
{
printf ("%9.4f", ar[index]);

if ((index % 6) == 5)
{
putchar ('\n');
}
}

if (n % 6)
{
putchar ('\n');
}
}

int my_comp (const void * p1, const void * p2)
{
const double * a1 = (const double *) p1, * a2 = (const double *) p2;

return (!(*a1 - *a2)) ? 0 : ((*a1 > *a2) ? 1 : -1);
}
54 changes: 54 additions & 0 deletions 16/16.19.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "../s_gets.h"

#define NAME_LEN 40

struct name
{
char f_name[NAME_LEN];
char l_name[NAME_LEN];
};

int comp (const void * p1, const void * p2);

int main (void)
{
struct name names[NAME_LEN];
int j;

printf ("Please enter names. \n");
for (j = 0; j < NAME_LEN; j ++)
{
printf ("Please enter first name: \n");
s_gets (names[j].f_name, NAME_LEN);
if (!(names[j].f_name[0]))
{
break;
}

printf ("Please enter last name: \n");
s_gets (names[j].l_name, NAME_LEN);

printf ("Please enter next name. \n");
}

(j != NAME_LEN) ? j ++ : (j = NAME_LEN);

qsort (names, j, sizeof (names[0]), comp);

printf ("This is the list of names you've entered: \n");
for (int p = 0; p < j; p ++)
{
printf ("%s %s \n", names[p].f_name, names[p].l_name);
}

return 0;
}

int comp (const void * p1, const void * p2)
{
const struct name * a1 = (const struct name *) p1, * a2 = (const struct name *) p2;

return (strcmp (a1 -> f_name, a2 -> f_name)) ?
strcmp (a1 -> f_name, a2 -> f_name) :
strcmp (a1 -> l_name, a2 ->l_name);
}
26 changes: 26 additions & 0 deletions 16/16.2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//预处理器指令从 '#' 开始, 长度为1逻辑行;
//格式为 "#预处理器指令 宏 替换体";

#include <stdio.h>

#define TWO 2 //可以注释;
#define OW "Consistency is the last refuge of the unimagina\
tive. - Oscar Wi\
lde" //反斜杠可以把define延伸一行;
#define FOUR TWO * TWO
#define PX printf ("X is %d. \n", x);
#define FMT "X is %d. \n"

int main (void)
{
int x = TWO;

PX;
x = FOUR;
printf (FMT, x);
printf ("%s\n", OW);
printf ("TWO: OW\n");
printf ("%d: %s\n", TWO, OW);

return 0;
}
Loading

0 comments on commit eff3ed5

Please sign in to comment.