栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > 资讯 > 高等教育 > 考研政策

c语言程序设计题(2)

c语言程序设计题(2)

(2)处理任意人数的学生成绩,学生成绩利用一维数组保存,人数由用户输入; 要求: 子函数1:输入并保存学生成绩,利用new函数申请内存 子函数2:完成平均成绩的求取 子函数3:完成获取内存的释放delete 源代码: #include<iostream.h> int * save(int n) { int *s = new int[n]; cout<<"please input the scores of every student:"<<endl; if(s==NULL) cout<<"memory allocating error!exit."<<endl; for(int i=0;i<n;i++) cin>>s[i]; return s; } void average( int b[],int x) { float aver,sum=0; for(int i=0;i<x;i++) {sum+=*b; b++;} aver=sum/x; cout<<"the average score is:"<<aver<<endl; } int free( int c[]) { delete []c; return 0; } void main(){ int n; int *scores; cout<<"please tell me the number of the students:"<<endl; cin>>n; scores=save(n); average(scores,n); free(scores);}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/news/1528850.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号