}
============================================================== 【程序44】题目:学习使用external的用法。 #include \#include \int a,b,c; void add() {
int a; a=3; c=a+b; }
void main() {
a=b=4; add();
printf(\ getch(); }
============================================================== 【程序45】题目:学习使用register定义变量的方法。 #include \#include \void main() {
register int i; int tmp=0;
for(i=1;i<=100;i++) tmp+=i;
printf(\ getch(); }
============================================================== 【程序46】题目:宏#define命令练习(1) #include \#include \#define TRUE 1 #define FALSE 0 #define SQ(x) (x)*(x) void main() {
int num; int again=1;
printf(\ while(again) {
printf(\ scanf(\
printf(\ if(num>=50) again=TRUE; else
again=FALSE; }
getch(); }
============================================================== 【程序47】题目:宏#define命令练习(2) #include \#include \
/*宏定义中允许包含两道衣裳命令的情形,此时必须在最右边加上\#define exchange(a,b) { \\
int t;\\ t=a;\\ a=b;\\ b=t;\\
} void main(void) {
int x=10; int y=20;
printf(\ exchange(x,y);
printf(\ getch(); }
============================================================== 【程序48】题目:宏#define命令练习(3) #define LAG > #define SMA < #define EQ == #include \#include \void main() {
int i=10; int j=20; if(i LAG j)
printf(\ else if(i EQ j)
printf(\ else if(i SMA j)
printf(\ else
printf(\ getch(); }
============================================================== 【程序49】题目:#if #ifdef和#ifndef的综合应用。 #include \#include \#define MAX
#define MAXIMUM(x,y) (x>y)?x:y #define MINIMUM(x,y) (x>y)?y:x void main() {
int a=10,b=20; #ifdef MAX
printf(\#else
printf(\#endif
#ifndef MIN
printf(\#else
printf(\#endif
#undef MAX #ifdef MAX
printf(\#else
printf(\#endif
#define MIN #ifndef MIN
printf(\#else
printf(\#endif getch(); }
============================================================== 【程序50】题目:#include 的应用练习
test.h 文件如下: #define LAG > #define SMA < #define EQ ==
主文件如下:
#include \一个新文件50.c,包含test.h*/ #include \#include \void main() {
int i=10; int j=20; if(i LAG j)
printf(\ else if(i EQ j)
printf(\ else if(i SMA j)
printf(\ else
printf(\ getch(); }
==============================================================
【程序51】题目:学习使用按位与 & 。 .程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1: #include \main() {
int a,b; a=077; b=a&3;
printf(\b&=7;
printf(\}
==============================================================
【程序52】题目:学习使用按位或 | 。程序分析:0|0=0; 0|1=1; 1|0=1; 1|1=1 #include \main() {
int a,b; a=077; b=a|3;
printf(\b|=7;
printf(\}
============================================================== 【程序53】题目:学习使用按位异或 ^ 。 程序分析:0^0=0; 0^1=1; 1^0=1; 1^1=0 #include \main() {
int a,b; a=077; b=a^3;
printf(\b^=7;
printf(\}
============================================================== 【程序54】题目:取一个整数a从右端开始的4~7位。 程序分析:可以这样考虑: (1)先使a右移4位。(2)设置一个低4位全为1,其余全为0的数。可用~(~0<<4)(3)将上面二者进行&运算。 main() {
unsigned a,b,c,d;
scanf(\b=a>>4; c=~(~0<<4); d=b&c;
printf(\}
============================================================== 【程序55】题目:学习使用按位取反~。 程序分析:~0=1; ~1=0; #include \main() {
int a,b; a=234; b=~a;
printf(\a=~a;
printf(\}
============================================================== 【程序56】题目:画图,学用circle画圆形。 /*circle*/
#include \main()
{int driver,mode,i; float j=1,k=1;
driver=VGA;mode=VGAHI; initgraph(&driver,&mode,\setbkcolor(YELLOW); for(i=0;i<=25;i++) {
setcolor(8);
circle(310,250,k); k=k+j; j=j+0.3; } }
============================================================== 【程序57】题目:画图,学用line画直线。 #include \main()
{int driver,mode,i; float x0,y0,y1,x1; float j=12,k;
driver=VGA;mode=VGAHI; initgraph(&driver,&mode,\setbkcolor(GREEN);
x0=263;y0=263;y1=275;x1=275; for(i=0;i<=18;i++) {
setcolor(5);
line(x0,y0,x0,y1); x0=x0-5; y0=y0-5; x1=x1+5; y1=y1+5; j=j+10; }
x0=263;y1=275;y0=263; for(i=0;i<=20;i++) {
setcolor(5);
line(x0,y0,x0,y1); x0=x0+5; y0=y0+5; y1=y1-5; } }
==============================================================
【程序58】题目:画图,学用rectangle画方形。 程序分析:利用for循环控制100-999个数,每个数分解出个位,十位,百位。 #include \main()
{int x0,y0,y1,x1,driver,mode,i; driver=VGA;mode=VGAHI; initgraph(&driver,&mode,\setbkcolor(YELLOW);
x0=263;y0=263;y1=275;x1=275; for(i=0;i<=18;i++) {
setcolor(1);
rectangle(x0,y0,x1,y1); x0=x0-5; y0=y0-5; x1=x1+5; y1=y1+5; }
settextstyle(DEFAULT_FONT,HORIZ_DIR,2); outtextxy(150,40,\line(130,60,480,60); setcolor(2);
circle(269,269,137); }
============================================================== 【程序59】题目:画图,综合例子。 # define PAI 3.1415926 # define B 0.809
# include \#include \main() {
int i,j,k,x0,y0,x,y,driver,mode; float a;
driver=CGA;mode=CGAC0; initgraph(&driver,&mode,\setcolor(3);
setbkcolor(GREEN); x0=150;y0=100; circle(x0,y0,10); circle(x0,y0,20); circle(x0,y0,50); for(i=0;i<16;i++) {
a=(2*PAI/16)*i;
x=ceil(x0+48*cos(a)); y=ceil(y0+48*sin(a)*B); setcolor(2); line(x0,y0,x,y);} setcolor(3);circle(x0,y0,60);
/* Make 0 time normal size letters */
settextstyle(DEFAULT_FONT,HORIZ_DIR,0); outtextxy(10,170,\getch();
setfillstyle(HATCH_FILL,YELLOW); floodfill(202,100,WHITE); getch();
for(k=0;k<=500;k++) {
setcolor(3);
for(i=0;i<=16;i++) {
a=(2*PAI/16)*i+(2*PAI/180)*k; x=ceil(x0+48*cos(a)); y=ceil(y0+48+sin(a)*B); setcolor(2); line(x0,y0,x,y); }