博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
实验6(2.0)
阅读量:5955 次
发布时间:2019-06-19

本文共 2863 字,大约阅读时间需要 9 分钟。

实验六:成绩统计器

1.定义5行3列实型二维数组,并用AVERAGE函数进行统计

2.采用二维循环从键盘给数组每个元素分别赋值,并加入数据检测机制(只接受介于0至100之间的浮点数据)

3.编写AVERAGE函数进行计算平均值

4.计算每个学生的平均分,并输出

5.计算每门课程的平均分,并输出

6.拥有简单的用户交互界面

代码:

1 #include 
2 #include
3 int main() 4 { 5 float AVERAGE(float a[], int n); 6 float grade[5][3]; 7 float student1[3],student2[3],student3[3],student4[3],student5[3]; 8 float subject1[5],subject2[5],subject3[5]; 9 float subav1, subav2, subav3;10 float stuav1, stuav2, stuav3, stuav4, stuav5;11 float k;12 int i, j;13 printf("==========================welcome to the system=============================\n");14 for (i = 1; i <= 5; i++)15 {16 for (j = 1; j <= 3; j++)17 {18 printf("===input the %dth subject grade of the %dth student===\n", j, i);19 aa:scanf_s("%f", &k);20 if (k <= 100 && k >= 0)21 {22 grade[i-1][j-1] = k;23 }24 else25 {26 printf("input the right grade!\n");27 goto aa;28 }29 }30 }31 system("CLS");32 printf("==============subject1========subject2==========subject3==\n");33 for (i = 1; i <= 5; i++)34 {35 printf("student%d %f %f %f\n", i, grade[i-1][0], grade[i-1][1], grade[i-1][2]);36 }37 printf("====================================================\n");38 for (i = 0; i < 5; i++)39 {40 subject1[i] = grade[i][0];41 subject2[i] = grade[i][1];42 subject3[i] = grade[i][2];43 }44 for (j = 0; j < 3; j++)45 {46 student1[j] = grade[0][j];47 student2[j] = grade[1][j];48 student3[j] = grade[2][j];49 student4[j] = grade[3][j];50 student5[j] = grade[4][j];51 }52 stuav1 = AVERAGE(student1, 3);53 stuav2 = AVERAGE(student2, 3);54 stuav3 = AVERAGE(student3, 3);55 stuav4 = AVERAGE(student4, 3);56 stuav5 = AVERAGE(student5, 3);57 subav1 = AVERAGE(subject1, 5);58 subav2 = AVERAGE(subject2, 5);59 subav3 = AVERAGE(subject3, 5);60 printf(" AVERAGE\n");61 printf("student1 %f\n", stuav1);62 printf("student2 %f\n", stuav2);63 printf("student3 %f\n", stuav3);64 printf("student4 %f\n", stuav4);65 printf("student5 %f\n", stuav5);66 printf("==================================\n");67 printf("subject1 %f\n", subav1);68 printf("subject2 %f\n", subav2);69 printf("subject3 %f\n", subav3);70 system("pause");71 return 0;72 }73 float AVERAGE(float a[],int n)74 {75 float sum=0;76 int i;77 for (i = 0; i < n; i++)78 {79 sum = sum + a[i];80 }81 return sum / n;82 }

 

演示:

改进方案:1.调整输出数据位数

     2.增加对文件读写的支持

(ver2.0)

转载于:https://www.cnblogs.com/p201821440018/p/10679908.html

你可能感兴趣的文章
DateTime字段控件值显示短格式的做法
查看>>
T-SQL 查询、修改数据表
查看>>
LeetCode-9-Palindrome Number
查看>>
js常用方法
查看>>
认识光圈0001
查看>>
c++矩阵运算库Eigen简介
查看>>
类的初始化过程
查看>>
在回调中获取Url参数
查看>>
AttachDispatch
查看>>
Money-去哪了每日站立会议
查看>>
POJ2146 Confusing Login Names [最小字符串编辑距离]
查看>>
forEach for 循环
查看>>
配置eclipse编写html/js/css/jsp/java时自动提示
查看>>
【莫队算法】【权值分块】bzoj3585 mex
查看>>
解决ScrollViewer嵌套的DataGrid、ListBox等控件的鼠标滚动事件无效
查看>>
CodeForces 501B - Misha and Changing Handles
查看>>
第二章 数学运算、数组、文字处理
查看>>
商品详情页面的显示
查看>>
欧几里德算法与扩展欧几里德算法
查看>>
Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring
查看>>