1、2016年5月17日5、6、7节 课一、实验目的及要求(1)掌握一维数组和二维数组的定义方法,以及其元素的访问形式。(2)掌握函数的定义和调用方法。(3)掌握函数实参和形参间的值传递关系。(4)了解窗数的恢套调用和递归调用。二、实验内容和原理应用函数和数组的概念及思路编程程序解决问题三、算法描述.实验步骤及结果每题要求描述算法(可以使用自然语言、传统流程图和N-S图进行描述)、加入 每题的程序代码。1 编程计算组合数错误!未找到引用源。#include long int fact (int n)if (n0)return 0;else if(n=01 In=l)return 1;elseret
2、urn n*fact (n-1);int main ()int m, k,p;pr intf (nPlease input m and k ; scanf (%d%*c%d, &m, &k);p=fact (m) / (fact (k) *fact (m-k); printf (np=%d,p);Fie EdH View Sech Project fluid Detug Fortran wi52.#include float fact (int n)float i, y;y=1000/(1+12*0. 01875);for (i=l; in; i+)y=(1000+y)/(1+12*0. 01
3、875);return y;int n;float y;printf (Please input n :;scanf (%dn);y=fact (n);printf (n%. 2fy);3.#include #define ROW 5#define COL 5int i, j, sum;int array ROW COL;for (i=0;R0W;for(j=0; jCCOL; j+)scanf(array i j); jCOL;printf (H%5darrayi j);pr intf (nn);for (i=0, sum=0;if (i=j)sum=array i j+sum;pr int
4、f (nThe sum of the elements on the two diagonals is : %dn sum);for (i=0, sum=l;for (j=0;if (i%2=0)&(j%2=0)sum=array i j*sum;printf (nTwo diagonals upward, column subscripts are even the productof each element is :,sum);mn c Code Blocks 13 12fir (drt Ww Scwch Profit BmM DK)ug fettJUHfll M W 4:O OB -y
5、 2111 H K ;4.#include int i, j, sumi, sum;int a ROW COL;ai j=i*ROW+j;%5d, a i j);sumi=a i j +sumi;sum=sum-sumi;sum=%d i+1, sumi, sum); sum%d=%dFie r x e a j o % X 匚OWOfkMMCCStMt heremMvc Cod Blocks 13.12priatf O .9UB1- )nne MetiMLai Mint)10 l:121)14151202:2223prinf (* printfreturnDAFileiAAViwacU Ha5
6、.#include void sort (int p , int n)int i, j, temp;n-l;for (j=i+l;if (pipjl)temp=p i;pj=temp;int ma in ()int num 9, i;enter 9 numbers: nn);9;scanf (H%d &num i);before the sorting:nn);printf (Hnum%d=%2d%2c, i+1, num i, (i+1)%3=0?/nz:f f);sort (num, 9);(i+l)%3=0?,n,:/ 9;pr intf (nnum %d =%2d%2c i+1, num四、调试过程描述每题在调试过程中出现的问题现象、原因及解决方法。5.指导教师评语及成绩:评语成绩等级格式规范、条理清晰,报告内容详细准确A( ) B()完成必选题题目完成的正确性A()B()程序书写的规范性本报告总成绩
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1