for (n=2;n<=10;n++) {
sn=sn+2*hn; /*第n次落地时共经过的米数*/ hn=hn/2; /*第n次反跳高度*/ }
printf(\第10次落地时共经过%f米\\n\ printf(\第10次反弹%f米\\n\ return 0; } 5-12
#include
int day,x1,x2; day=9; x2=1;
while(day>0)
{x1=(x2+1)*2; /*第1天的桃子数是第2天桃子数加1后的2倍.*/ x2=x1; day--; }
printf(\ return 0; } 5-13
#include
float a,x0,x1;
printf(\ scanf(\ x0=a/2;
x1=(x0+a/x0)/2; do
{x0=x1;
x1=(x0+a/x0)/2;
}while(fabs(x0-x1)>=1e-5);
printf(\ is %8.5f\\n\ return 0; }
5-14
#include
{double x1,x0,f,f1; x1=1.5; do
{x0=x1;
f=((2*x0-4)*x0+3)*x0-6; f1=(6*x0-8)*x0+3; x1=x0-f/f1;
}while(fabs(x1-x0)>=1e-5);
printf(\ return 0; } 5-15
#include
{float x0,x1,x2,fx0,fx1,fx2; do
{printf(\ scanf(\ fx1=x1*((2*x1-4)*x1+3)-6; fx2=x2*((2*x2-4)*x2+3)-6; }while(fx1*fx2>0); do
{x0=(x1+x2)/2;
fx0=x0*((2*x0-4)*x0+3)-6; if ((fx0*fx1)<0) {x2=x0; fx2=fx0; } else {x1=x0; fx1=fx0; }
}while(fabs (fx0)>=1e-5); printf(\ return 0; }
5-16
#include
for (i=0;i<=3;i++) {for (j=0;j<=2-i;j++) printf(\
for (k=0;k<=2*i;k++) printf(\ printf(\ }
for (i=0;i<=2;i++) {for (j=0;j<=i;j++) printf(\
for (k=0;k<=4-2*i;k++) printf(\ printf(\ }
return 0; } 5-17
#include
char i,j,k; /*是a的对手;j是b的对手;k是c的对手*/ for (i='x';i<='z';i++) for (j='x';j<='z';j++) if (i!=j)
for (k='x';k<='z';k++) if (i!=k && j!=k) if (i!='x' && k!='x' && k!='z') printf(\--%c\\nB--%c\\nC--%c\\n\ return 0; }
第6章利用数组处理批量数据142 6.1怎样定义和引用一维数组142 6.1.1怎样定义一维数组143 6.1.2怎样引用一维数组元素144
6.1.3一维数组的初始化145 6.1.4一维数组程序举例146
6.2怎样定义和引用二维数组148 6.2.1怎样定义二维数组149
6.2.2怎样引用二维数组的元素150 6.2.3二维数组的初始化151 6.2.4二维数组程序举例152 6.3字符数组154
6.3.1怎样定义字符数组154 6.3.2字符数组的初始化155
6.3.3怎样引用字符数组中的元素155 6.3.4字符串和字符串结束标志156 6.3.5字符数组的输入输出159 6.3.6使用字符串处理函数161 6.3.7字符数组应用举例165 习题168 6-1
#include
{int i,j,n,a[101];
for (i=1;i<=100;i++) a[i]=i; a[1]=0;
for (i=2;i for (i=2,n=0;i<=100;i++) { if(a[i]!=0) {printf(\ n++; } if(n==10) {printf(\ n=0; } } printf(\ return 0; } 6-2 #include {int i,j,min,temp,a[11]; printf(\ for (i=1;i<=10;i++) {printf(\ scanf(\ } printf(\ printf(\ for (i=1;i<=10;i++) printf(\ printf(\ for (i=1;i<=9;i++) {min=i; for (j=i+1;j<=10;j++) if (a[min]>a[j]) min=j; temp=a[i]; a[i]=a[min]; a[min]=temp; } printf(\ for (i=1;i<=10;i++) printf(\ printf(\ return 0; } 6-3 #include int a[3][3],sum=0; int i,j; printf(\ for (i=0;i<3;i++) for (j=0;j<3;j++) scanf(\ for (i=0;i<3;i++) sum=sum+a[i][i]; printf(\