-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
caa5ae9
commit 5061d81
Showing
101 changed files
with
2,605 additions
and
313 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
//声明结构; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} |
Oops, something went wrong.