文档详情

广工 c语言 经典例题(A classical example of a guanggong c language).doc

发布:2017-07-23约1.42万字共35页下载文档
文本预览下载声明
广工 c语言 经典例题(A classical example of a guanggong c language) Please fill in the appropriate content only at the program vacancy Implementation function: enter 5 integers in turn to calculate their sum and output. * * * * * * * * * * / # include stdio, h Void main () {int I, sum = 0 n; For (I = 1; I = 5; i++) {the scanf ( % d , n); Sum = sum + n. } Printf ( sum = % d , sum); } Please fill in the appropriate content only at the program vacancy Implementation function: enter an integer greater than 1 to n, in the same loop statement The number of odd and even integers between 1 and n is calculated separately. * * * * * * * * * * / # include stdio, h Void main () {int odd, even, I, n. The scanf ( % d , n); For (I = 1, odd = 0, even = 0; I = n + I = 2) { Odd + = I; If (I = n + 1) Even + = I + 1; } Printf ( the sum of the odd = % d , odd); / * the sum of odd Numbers * / Printf ( the sum of even = % d \ n , even); / * the sum of even Numbers * / } [problem 5.030] the system is given an external integer variable n and a long integer variable f (it doesnt need to be defined by itself). Write the program, n factorial n factorial. And will The results are stored in f. For example, when n is equal to 6, f is equal to 6. = 1 * 2 *... * 6 = 720. Note: 0! = 1. * * * * * * * * * * / Void main () { Int a = 1; F = 1; If (n = = 0) f = 1; The do { F = f * a; A + = 1; } While (a = n); } [problem 5.032] the system is given an external integer variable n and a long integer variable f (no It needs to be defined by itself. Write the program, n factorial n factorial. ! , and the result Store it to f. The definition of double factorial is: When n is odd, n! For the product of all the odd Numbers of n, Such as: 7!!!!! X 3 x 5 x 7 = 1. When n is even, the product of all even Numbers that are not greater than n (except for 0), Such as: 8!!!!! = 2 x 4 x 6 x 8. * * * * * * * * * * / Void main () { Int a; F = 1; If (n = = 0) f = 1; Else if (n % 2 = = 0) a = 2; Else a = 1; The do { F = f * a
显示全部
相似文档