1http://learn.tsinghua.edu.cn
Email,qiaolin@cic.tsinghua.edu.cn
Tel,62792961
2http://learn.tsinghua.edu.cn







3http://learn.tsinghua.edu.cn
4http://learn.tsinghua.edu.cn





5http://learn.tsinghua.edu.cn

– C99 const

– VANT


6http://learn.tsinghua.edu.cn





7http://learn.tsinghua.edu.cn
8http://learn.tsinghua.edu.cn
– C



9http://learn.tsinghua.edu.cn


– x = x;


10http://learn.tsinghua.edu.cn


– goto

11http://learn.tsinghua.edu.cn



– C
12http://learn.tsinghua.edu.cn
assert()
#include <assert.h>
void ProcessString(char* str)
{
assert( str != NULL );
assert( *str != '\0' );
<<
}
assert() assert.h
NDEBUG
str
13http://learn.tsinghua.edu.cn






14http://learn.tsinghua.edu.cn
m n
int gcd( int m,int n )
{
int r;
start:
r = m % n;
if( r == 0 )
return n;
m = n;
n = r;
goto start;
}
mn
mn
1m nr
2r0n
3nmrn1
15http://learn.tsinghua.edu.cn
16http://learn.tsinghua.edu.cn





17http://learn.tsinghua.edu.cn
#include <stdio.h> /* */
#define PI 3.14159265 /* PI,*/
float radius,height,volume; /* */
void main() /* */
{
/* */
printf(“This program computes the volume of the cylinder.\n“);
printf(“Please input the radius value:,);
scanf(“%f“,&radius);
printf(“Please input the height value:,);
scanf(“%f“,&height);
/* */
volume = PI * radius * radius * height;
/* */
printf(“The volume of the cylinder is %f\n“,volume);
}
18http://learn.tsinghua.edu.cn




19http://learn.tsinghua.edu.cn
#include <stdio.h> /* */
#define PI 3.14159265 /* PI,*/
float radius,height,volume; /* */
void Input(); /* */
void Compute(); /* */
void Output(); /* */
void main() /* */
{
Input();
Compute();
Output();
}
20http://learn.tsinghua.edu.cn
void Input()
{
printf(“This program computes the volume of the cylinder.\n“);
printf(“Please input the radius value:,);
scanf(“%f“,&radius);
printf(“Please input the height value:,);
scanf(“%f“,&height);
}
void Compute()
{
volume = PI * radius * radius * height;
}
void Output()
{
printf(“The volume of the cylinder is %f\n“,volume);
}
——
21http://learn.tsinghua.edu.cn



1
2
22http://learn.tsinghua.edu.cn
float radius,height,volume;
float GetFloatValue(char* prompt);
float GetFloatValue(char* prompt)
{
float t; printf(“%s“,prompt); scanf(“%f“,&t); return t;
}
void Input()
{
printf(“This program computes the volume of the cylinder.\n“);
/* GetFloatValueradius */
radius = GetFloatValue(“Please input the radius value:,);
/* GetFloatValueheight */
height = GetFloatValue(“Please input the height value:,);
}
23http://learn.tsinghua.edu.cn




24http://learn.tsinghua.edu.cn





25http://learn.tsinghua.edu.cn
1,8 3 2fc
c f
#include <stdio.h> /* */
float f,c; /* */
float GetFloatValue(char* prompt); /* */
void Input(); /* */
void Compute(); /* */
void Output(); /* */
void main() /* */
{
Input();
Compute();
Output();
}
26http://learn.tsinghua.edu.cn
float GetFloatValue(char* prompt)
{
float t; printf(“%s“,prompt); scanf(“%f“,&t); return t;
}
void Input()
{
c = GetFloatValue(“Please input temperature value(C):,);
}
void Compute()
{
f = c * 1.8 + 32;
}
void Output()
{
printf(“Temperature Value(F),%f\n“,f);
}
27http://learn.tsinghua.edu.cn
#include <stdio.h>
float f,c;
float GetFloatValue(char* prompt);
void Input();
void Compute();
void Output();
void main()
{
Input();
Comput();
Output();
}
#include <assert.h>
assert(c > –273.13);
#define ABSOLUTE_ZERO–273.13
ABSOLUTE_ZERO);
28http://learn.tsinghua.edu.cn
#include <stdio.h>
#include <assert.h>
#define ABSOLUTE_ZERO–273.13
float f,c;
void Compute()
{
f = c * 1.8 + 32;
}
void main()
{
Input();
assert(c > ABSOLUTE_ZERO);
Compute();
Output();
}
f cfloat1.8double32intcdouble32
doubledoublefloatf
F
F + 32.0F;
29http://learn.tsinghua.edu.cn
132
– 1 8