c语言实验8,C语言编程实验8.doc

C语言编程实验8

实验8 指针(P148-P158)

说明:

完成以下实验内容后,将本文档改名为“实验8_班级_学号_姓名.doc”,并按规定提交。

第一部分:练习题

练习题1

程序代码#include

#define ARR_SIZE 40

int FindMax(int score[], long num[],int n,long *pMaxNum);

void main()

{

int score[ARR_SIZE],maxScore,n,i;

long num[ARR_SIZE],maxNum;

printf("Please enter total number:");

scanf("%d",&n);

printf("Please enter the number and score:\n");

for (i=0;i

{

scanf("%ld%d",&num[i],&score[i]);

}

maxScore=FindMax(score,num,n,&maxNum);

printf("maxScore=%d,maxNum=%ld\n",maxScore,maxNum);

}

int FindMax(int score[],long num[],int n,long *pMaxNum)

{

int i;

int maxScore;

maxScore=score[0];

*pMaxNum=num[0];

for (i=1;i

{

if (score[i]>maxScore)

{

maxScore=score[i];

*pMaxNum=num[i];

}

}

return(maxScore);

}程序运行截图

用二维数组和指针变量作为函数参数,编程打印3个班学生的某门课程成绩的最高分,并指出具有该最高分成绩的学生是第几个班的第几个学生。程序代码#include

#define CLASS 3

#define STU 10

#define ARR_SIZE 40

int FindMax(int score[CLASS][ARR_SIZE], int m,int n,int *pRow,int *pCol);

void main()

{

int score[CLASS][ARR_SIZE],maxScore,n,i,j,row,col;

printf("Please enter student number in a class:");

scanf("%d",&n);

printf("Please enter score:\n");

for (i=0;i

{

for(j=0;j

{

scanf("%d",&score[i][j]);

}

}

maxScore=FindMax(score,n,CLASS,&row,&col);

printf("maxScore=%d,class=%d,number=%d\n",maxScore,row+1,col+1);

}

int FindMax(int score[][ARR_SIZE],int n,int m,int *pRow,int *pCol)

{

int i,j,maxScore;

maxScore=score[0][0];

*pRow=0;

*pCol=0;

for (i=0;i

{

for(j=0;j

{

if(score[i][j]>maxScore)

{

maxScore=score[i][j];

*pRow=i;

*pCol=j;

}

}

}

return(maxScore);

}程序运行截图问题解答思考题1能否使用二维数组或者而为数组的行指针作为函数参数进行编程实现呢?可以,两者都可以作为指针指向函数,从而进行地址传递思考题2利用动态内存分配,编写计算任意m行n列二维数组中最大值的函数。程序代码#include

#include

int m;

int n;

int main()

{

int *p;

int *q;

printf("输入行数m列数n: ");

scanf("%d %d",&m,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值