100个经典C语言算法 下载本文

void main() { a=b=4; add();

printf(\}

题目:学习使用register定义变量的方法。

___________________________________________________________________

程序源代码: void main() {

register int i; int tmp=0;

for(i=1;i<=100;i++) tmp+=i;

printf(\}

题目:宏#define命令练习(1)

___________________________________________________________________

程序源代码:

#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; } }

题目:宏#define命令练习(2)

___________________________________________________________________

程序源代码:

#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(\}

题目:宏#define命令练习(3)

___________________________________________________________________

程序源代码: #define LAG > #define SMA < #define EQ ==

#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(\}

题目:#if #ifdef和#ifndef的综合应用。

___________________________________________________________________

程序源代码:

#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

}

题目:#include 的应用练习

___________________________________________________________________

程序源代码:

test.h 文件如下: #define LAG > #define SMA < #define EQ ==

#include \一个新文件50.c,包含test.h*/ #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(\}

题目:学习使用按位与 & 。

___________________________________________________________________

程序分析:0&0=0; 0&1=0; 1&0=0; 1&1=1

___________________________________________________________________

程序源代码:

#include \main() {

int a,b; a=077;