nankai100_1
2015-11-25 09:47
423 查看
/// @file exam_x_x.cpp /// @brief /** 1: 第1题 m个人的成绩存放在score数组中,请编写函数fun, 它的功能是:将低于平均分的人作为函数值返回,将低于平均分的分数放在below所指定的函数中。 */ #include <windows.h> #include <stdlib.h> #include <stdio.h> #include <crtdbg.h> #include <conio.h> int fun(int score[], int m, int below[]); void print_int_array(char* pcTip, int iAry[], int iSizeAry); int main(int argc, char *argv[ ], char *envp[ ]) { int iLowScoreCnt = 0; int score[] = {10, 20, 30, 40, 50, 60, 70, 80, 90}; int below[9] = {0}; print_int_array("score[] = ", score, sizeof(score) / sizeof(score[0])); iLowScoreCnt = fun(score, sizeof(score) / sizeof(score[0]), below); printf("iLowScoreCnt = %d\n", iLowScoreCnt); print_int_array("below[] = ", score, iLowScoreCnt); /** run result score[] = 10 20 30 40 50 60 70 80 90 iLowScoreCnt = 4 below[] = 10 20 30 40 */ printf("END, press any key to quit\n"); getchar(); return 0; } int fun(int score[], int m, int below[]) { int i = 0; int iScoreAll = 0; int iScoreAverage = 0; int iBelowAverageCnt = 0; /// 算平均分 for (i = 0; i < m; i++) { iScoreAll += score[i]; } iScoreAverage = (int)(1.0f * iScoreAll / m); /// 将低于平均分的成绩放入below for (i = 0; i < m; i++) { if (score[i] < iScoreAverage) { iBelowAverageCnt++; below[i] = score[i]; } } return iBelowAverageCnt; } void print_int_array(char* pcTip, int iAry[], int iSizeAry) { int i = 0; int iPos = 0; if (NULL != pcTip) { printf("%s\n", pcTip); } for (i = 0; i < iSizeAry; i++) { if (0 == iPos++ % 8) { printf("\n"); } printf("%d ", iAry[i]); } printf("\n"); }
相关文章推荐
- HaiHongOJ 1003 God Wang
- Installation error: INSTALL_FAILED_VERSION_DOWNGRADE
- RAID-4与模2和
- 学习笔记7:wait(),notify()与notifyAll()及消费者生产者小案例
- 从vfs_write()到ocfs2_file_aio_write()
- ocfs2_file_aio_write()
- lighttpd, web.py, spawning fcgi failed
- odoo worker 异常Exception("bus.Bus unavailable")
- POJ 3691 DNA repair (AC自动机 + dp)
- LightOJ 1038 - Race to 1 Again(期望DP)
- http://m.blog.csdn.net/blog/jimy86022/20995481 [zhuanzai] -------celllinehidden
- leetcode_182_duplicate_emails
- An error has occurred. See error log for more details.关于这个问题的小谈
- Daily Scrum - 11/24
- Time to sail!
- leetcode 70:Climbing Stairs
- 从B树、B+树、B*树谈到R 树 http://blog.csdn.net/v_JULY_v/article/details/6530142/
- POJ 3250-Bad Hair Day【栈】
- CenterOS6.5 配置sendmail
- 在AIX中查看文件大小