Skip to content

Commit

Permalink
upload 4.30, happy holiday
Browse files Browse the repository at this point in the history
  • Loading branch information
TGSpock123 committed Apr 30, 2024
1 parent caa5ae9 commit 5061d81
Show file tree
Hide file tree
Showing 101 changed files with 2,605 additions and 313 deletions.
5 changes: 5 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

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

18 changes: 18 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

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

4 changes: 2 additions & 2 deletions 13/myPow.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ double myPow(double x, long n)
{
return 1;
}
else;

if (n < 0)
{
n = -n;
x = 1 / x;
}
else;

while (n != 1)
{
if (n % 2 == 1)
Expand Down
29 changes: 28 additions & 1 deletion 13/myPow.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,29 @@
double myPow(double x, long n);
double myPow(double x, long n)
{
double y = 1;

if (x == 1 || n == 0)
{
return 1;
}

if (n < 0)
{
n = -n;
x = 1 / x;
}

while (n != 1)
{
if (n % 2 == 1)
{
y *= x;
}
else;
x *= x;
n /= 2;
}

return y * x;
}

3 changes: 0 additions & 3 deletions 13/myPow.h~

This file was deleted.

2 changes: 1 addition & 1 deletion 14/14.1.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//加强版;
#include "s_gets.h"
#include "../s_gets.h"
#define MAXTITL 30
#define MAXBK 100
//声明结构;
Expand Down
4 changes: 2 additions & 2 deletions 14/14.14.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "s_gets.h"
#include "../s_gets.h"
#define MAXTITL 40
#define MAXAUTL 40
#define MAXBKS 10
Expand Down Expand Up @@ -63,7 +63,7 @@ int main (void)
puts ("Here is the list of your books: ");
for (index = 0; index < count; index ++)
{
printf ("%s by %s: $%.2f \n", library[count].title, library[count].author, library[count].value);
printf ("%s by %s: $%.2f \n", library[index].title, library[index].author, library[index].value);
}
fwrite (&library[filecount], size, count - filecount, pbooks);
}else
Expand Down
Binary file modified 14/14.14.exe
Binary file not shown.
88 changes: 88 additions & 0 deletions 14/14.15.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#include <stdio.h>

//这个结构有点好玩, 可录入的值为定义的几个值之一, 并且每录入一个新值就会洗掉先前录入的值;
union hold
{
int digit;
double bigfl;
char letter;
};

int main (void)
{
union hold save[10]; //一个内含十个hold类型的数组;
union hold * pu; //一个指向hold类型的指针;
union hold valA; //一个hold类型的union变量;
int x;

valA.letter = 'A';
union hold valB = valA; //使用另一个联合初始化联合;
union hold valC = {88}; //初始化联合中的某个成员;
union hold valD = {.bigfl = 118.2}; //指定初始化器;

valA.digit = 23; //把23存储在valA, 占用2字节;
valA.bigfl = 2.0; //清除23并把2.0存储在valA, 占用8字节;
valA.letter = 'h'; //清除2.0并把'h'存储在valA, 占用1字节;

pu = &valA;
x = pu -> digit; //相当于x = valA.digit;

/*
x = (pu -> letter) * 3.02 这种写法是错误的;
*/

//以下是一段车辆管理代码;
struct owner //车主信息;
{
char socsecurity[12];
//代码;
};
struct leasecompany //租赁者信息;
{
char name[40];
char headquarters[40];
//代码;
};

union data //存储信息的联合;
{
struct owner owncar;
struct leasecompany leasecar;
};

struct car_data
{
char make[15];
int status; //status为判断值, 当status为0时写车主信息入*结构变量名*.ownerinfo.owncar.socsecurity,
//当status为1时则写租赁者信息;
union data ownerinfo;
//代码;
};

//用匿名联合重写以上代码;
struct owner1 //车主信息;
{
char socsecurity[12];
//代码;
};
struct leasecompany1 //租赁者信息;
{
char name[40];
char headquarters[40];
//代码;
};
struct car_data1
{
char make[15];
int status; //status为判断值, 当status为0时写车主信息入*结构变量名*.owncar.socsecurity,
//当status为1时则写租赁者信息;
union
{
struct owner1 owncar;
struct leasecompany1 leasecar;
};
//代码;
};

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

int main (void)
{
enum spectrum //green = 302, blue = 303 ... ;
{
red = 100, orange = 300, yellow = 301, green, blue, violet, purple
} color;

for (color = blue; color != yellow; (color < yellow) ? color ++ : color --);

printf ("%u %u %u", color, red, purple);

return 0;
}
69 changes: 69 additions & 0 deletions 14/14.17.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include "../s_gets.h"
#define LEN 30

enum spectrum
{
red, orange, yellow, green, blue, violet, purple
};

const char * colors[] = {
"red", "orange", "yellow", "green", "blue", "violet", "purple"
};

int main (void)
{
char choice[LEN];
enum spectrum color;
bool color_is_found = false;

puts ("Enter a color (empty line to quit): ");

while ((s_gets(choice, LEN)) && (choice[0]))
{
for (color = red; color <= purple; color ++)
{
if (!(strcmp (choice, colors[color])))
{
color_is_found = true;
break;
}
}

if (color_is_found)
{
switch (color)
{
case red:
puts ("Rose are red. ");
break;
case orange:
puts ("Poppies are orange. ");
break;
case yellow:
puts ("Sunflowers are yellow. ");
break;
case green:
puts ("Grass is green. ");
break;
case blue:
puts ("Bluebells are blue. ");
break;
case violet:
puts ("Violets are violet. ");
break;
case purple:
puts ("Lavenders are purple. ");
break;
}
}else
{
printf ("I don't know about %s. \n", choice);
}

color_is_found = false;
puts ("Please enter Next color: ");
}
puts ("Thank you for using. ");

return 0;
}
79 changes: 79 additions & 0 deletions 14/14.18.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <stdio.h>
#define ASD struct c \
{ \
int a; \
int b; \
}
#define STRING1 char *

typedef int arr5[5];
typedef arr5 * p_arr5;
typedef p_arr5 arrp10[10];

typedef char (* FRPTC (void)) [5];
typedef unsigned char BYTE;
typedef char * STRING;
typedef struct complex
{
float real;
float imag;
}COMPLEX;


int main (void)
{
ASD s;
struct c asd;
BYTE x, y[10], * z;
STRING name, sign; //等价于 char * name, * sign;
STRING1 name1, sign1; //等价于 char * name, sign; 注意只有name是指针;
COMPLEX com = {
3.0, 6.0
};
int board[8][8];
int ** ptrr;
int * risks[10]; //一个10元素数组, 每个元素为一个(指向int元素的指针);
int (* rusks)[10]; //一个指向包含10个(int元素)的数组的指针;
int * oof[3][4]; //一个3 * 4元素数组, 每个元素为一个(指向int元素的指针);
int (* uuf)[3][4]; //一个指向包含3 * 4个(int元素)的数组的指针;
int (* uof[3])[4]; //一个3元素数组, 每个元素为一个(指向包含4个(int元素)的数组)的指针;
char fup (int k);
char * fump (int k); //返回(char指针)的函数;
char (* frump) (int k); //指向(返回类型为char的函数)的指针;
char (* flump[3]) (int k); //一个3元素数组, 每个元素为一个指向(返回类型为char的函数)的指针;
frump = &fup;
for (int n = 0; n < 3; flump[n] = frump, n ++);

s.b = 1;
asd.a = 2;
printf ("%s \n", fump (0));

arr5 togs; //含有5个(int元素)的数组;
p_arr5 p2; //一个指向(含有5个(int元素)的数组)的指针;
arrp10 ap; //一个内含10个(指向(含有5个(int元素)的数组)的指针)的数组;

int (* pf)(const char *, ...); //一个指向函数的指针;
pf = printf; //指的是printf;

(*pf)("HELLO PRINTF! \n"); //调用;
pf ("HELLO PRINTF! \n"); //第二种调用;

function1 (sqrt); //传递地址;
function2 (sqrt (4.0)); //传递返回值;

return 0;
}
char * fump (int k)
{
if (k)
{
return ("sdcs");
}else
{
return ("etwt");
}
}
char fup (int k)
{
return 'm';
}
Loading

0 comments on commit 5061d81

Please sign in to comment.