文档详情

7计算指定个数的数中奇偶数的个数及方差(Calculate the number and variance of odd even Numbers of the number of specified Numbers).doc

发布:2017-07-21约1.14万字共17页下载文档
文本预览下载声明
7计算指定个数的数中奇偶数的个数及方差(Calculate the number and variance of odd even Numbers of the number of specified Numbers) No. 52 sets Read the 200 integers in the file in.dat into array xx. Please prepare jsValue () function, requirement: find out the value in array xx for cnt1 odd number and the number of values for the even cnt2 xx and array subscript is even elements (including index of 0) arithmetic average of the element value pj. Result cnt1, cnt2, pj output to out.dat. 【 reference 】 Int I; Cnt1 = 0; Cnt2 = 0; Pj = 0; / * for loop statement computes the number of the number of odd Numbers in the array xx, cnt1 and number of even Numbers, and the number of elements of the array xx with an even number of elements and * / For (I = 0; I N; I + +) / / cyclic variable I starts at 0, increments one at a time until its value is less than N { If (xx [I] % 2) cnt1 + +; / / if the value of xx [I] is odd, the variable cnt1 plus 1 The else cnt2 + +; / / otherwise, the value of xx [I] is even and the variable cnt2 plus 1 If (I % 2 = = 0) pj + = xx [I]; / / if the array xx subscript I is even, then the value of xx [I] is added to the variable pj } Pj / = 100.0; The / / variable pj divided by 100.0 gives the average value of the element value of the array xx subscript I to even number fifty-three Read the 200 integers in the text in.dat to the array xx. Please prepare the jsValue () function to find out that the array in the array xx is an odd number of cnt1 and the number of even Numbers cnt2 and the array xx index is the odd number of element values pj. Results: cnt1, cnt2, pj output to out.dat. 【 reference 】 Int I; Cnt1 = 0; Cnt2 = 0; Pj = 0; For (I = 0; I N; I + +) { If (xx [I] % 2) cnt1 + +; The else cnt2 + +; If (I % 2) pj + = xx [I]; / / if the array xx index I is odd, the value of xx [I] is added to the variable pj } Pj / = 100.0; fifty-four There are a number of positive integers of four decimal digits in in.dat, and the function ReadDat () reads these positive integers and de
显示全部
相似文档