最新《C语言程序设计》(苏小红) 课后习题答案 高等教育出版社资料 下载本文

精品文档

int main() {

int score[N],n,max,num,t; long num[N];

t=FindMax(score,n); max=score[t]; num=num[t];

printf(\return 0; }

int ReadScore(int score[],long num[]) {

int i=-1; do{

i++;

printf(\ student's ID and score:\scanf(\}while(num[i]>0&&score[i]>=0); return i; }

int FindMax(int score[],long num[],int n) {

int max,i;

max=score[0]; for(i=1;i

if(score[i]>max)

max=score[i];

}

return i; }

8.7 #include #define N 40 int Read(int a[]);

int ChangeArry(int a[],int n); int main() {

int a[N],n;

printf(\return 0; }

int Read(int a[]) {

int i;

精品文档

精品文档

for(i=0;i<9;i++) {

printf(\ a:\scanf(\return i;

}

int ChangeArry(int a[],int n) {

int max,min,i,maxpos,minpos,term; max=min=score[0]; for(i=1;i

if(a[i]>max) max=score[i]; maxpos=n; else(a[i]

return a[i]; }

8.10 #include #define N 5 void main() {

int a[N][N]; int sum = 0; int i, j;

printf(\请输入一个%d*%d 的矩阵\\n\for(i = 0; i < N; i++) {

for(j = 0; j < N; j++) {

scanf(\} }

for(i = 0; i < N; i++) {

for(j = 0; j < N; j++) {

精品文档

精品文档

if(i == j || i + j == N - 1)

sum=sum+a[i][j]; }

}

printf(\对角线元素之和为:%d\\n\} 8.11 #include #define N 2 #define M 3 void main() {

int a[N][M],b[N][M];

int i,j,sum1=0,sum2=0,sum=0;

printf(\请输入一个%d*%d 的矩阵\\n\for(i = 0; i

for(j = 0; j< M; j++) {

scanf(\sum1=sum1+a[i][j]; } }

printf(\请输入一个%d*%d 的矩阵\\n\for(i = 0; i

for(j = 0; j

scanf(\sum2=sum2+a[i][j]; } }

sum=sum1+sum2;

printf(\}

8.12 #include #define N 7

void YangHui(int a[N][N],int n); void main() {

int i,j,n,b[N][N]; printf(\ n:\scanf(\YangHui(b,n); for(i=0;i

精品文档

精品文档

{

for(j=0;j<=i;j++) {

printf(\}

printf(\}

}

void YangHui(int a[N][N],int n) {

int i,j;

for(i=0;i

a[i][0]=1; a[i][i]=1; }

for(i=2;i

for(j=1;j

a[i][j]=a[i-1][j-1]+a[i-1][j]; } }

8.13 #include #define N 12 void main() {

int i;

int f[N]={1,1};

printf(\printf(\for(i=2;i

f[i]=f[i-1]+f[i-2];

printf(\} }

8.14 #include #include #include #define N 6000 void main() {

int a[N],i;

int b1=0,b2=0,b3=0,b4=0,b5=0,b6=0;

精品文档