Loop with the parameter
For1. Given integers K and N (N > 0), output the number K N times.
For2. Given two integers A and B (A < B), output in ascending order all integers in the range A to B (including A and B). Also output the amount N of these integers.
For3. Given two integers A and B (A < B), output in descending order all integers in the range A to B (excluding A and B). Also output the amount N of these integers.
For4. Given the price of 1 kg of sweets (as a real number), output the cost of 1, 2, …, 10 kg of these sweets.
For5°. Given the price of 1 kg of sweets (as a real number), output the cost of 0.1, 0.2, …, 1 kg of these sweets.
For6. Given the price of 1 kg of sweets (as a real number), output the cost of 1.2, 1.4, …, 2 kg of these sweets.
For7. Given two integers A and B (A < B), find the sum of all integers in the range A to B inclusive.
For8. Given two integers A and B (A < B), find the product of all integers in the range A to B inclusive.
For9. Given two integers A and B (A < B), find the sum of squares of all integers in the range A to B inclusive.
For10. Given an integer N (> 0), find the value of a following sum (as a real number): 1 + 1/2 + 1/3 + … + 1/N.
For11. Given an integer N (> 0), find the value of a following sum (as an integer): N2 + (N + 1)2 + (N + 2)2 + … + (2·N)2.
For12°. Given an integer N (> 0), find the value of a following product of N factors: 1.1 · 1.2 · 1.3 · … .
For13°. Given an integer N (> 0), find the value of the following expression of N terms with alternating signs: 1.1 − 1.2 + 1.3 − … . Do not use conditional statements.
For14. Given an integer N (> 0), compute N2 by means of the formula N2 = 1 + 3 + 5 + … + (2·N − 1). Output the value of the sum after addition of each term. As a result, squares of all integers in the range 1 to N will be output.
For15°. Given a real number A and an integer N (> 0), find A raised to the power N (i. e., the product of N values of A): AN = A·A· … ·A.
For16°. A real number A and an integer N (> 0) are given. Using one loop-statement compute and output powers AK for all integer exponents K in the range 1 to N.
For17. A real number A and an integer N (> 0) are given. Using one loop-statement compute the sum 1 + A + A2 + A3 + … + AN.
For18. A real number A and an integer N (> 0) are given. Using one loop-statement compute the expression 1 − A + A2 − A3 + … + (−1)N·AN. Do not use conditional statements.
For19°. Given an integer N (> 0), find the value of a following product: N! = 1·2·…·N (N–factorial). To avoid the integer overflow, compute the product using a real variable and output the result as a real number.
For20°. An integer N (> 0) is given. Using one loop-statement compute the sum 1! + 2! + 3! + … + N!, where N! (N–factorial) is the product of all integers in the range 1 to N: N! = 1·2·…·N. To avoid the integer overflow, compute the sum using real variables and output the result as a real number.
For21. An integer N (> 0) is given. Using one loop-statement compute the sum 1 + 1/(1!) + 1/(2!) + 1/(3!) + … + 1/(N!), where N! (N–factorial) is the product of all integers in the range 1 to N: N! = 1·2·…·N. The result is an approximate value of the constant e = exp(1).
For22. A real number X and an integer N (> 0) are given. Compute the expression 1 + X + X2/(2!) + … + XN/(N!) (N! = 1·2·…·N). The result is an approximate value of exp(X).
For23. A real number X and an integer N (> 0) are given. Compute the expression X − X3/(3!) + X5/(5!) − … + (−1)N·X2·N+1/((2·N+1)!) (N! = 1·2·…·N). The result is an approximate value of sin(X).
For24. A real number X and an integer N (> 0) are given. Compute the expression 1 − X2/(2!) + X4/(4!) − … + (−1)N·X2·N/((2·N)!) (N! = 1·2·…·N). The result is an approximate value of cos(X).
For25. A real number X (|X| < 1) and an integer N (> 0) are given. Compute the expression X − X2/2 + X3/3 − … + (−1)N−1·XN/N. The result is an approximate value of ln(1 + X).
For26. A real number X (|X| < 1) and an integer N (> 0) are given. Compute the expression X − X3/3 + X5/5 − … + (−1)N·X2·N+1/(2·N+1). The result is an approximate value of atan(X).
For27. A real number X (|X| < 1) and an integer N (> 0) are given. Compute the expression X + 1·X3/(2·3) + 1·3·X5/(2·4·5) + … + + 1·3·…·(2·N−1)·X2·N+1/(2·4·…·(2·N)·(2·N+1)). The result is an approximate value of asin(X).
For28. A real number X (|X| < 1) and an integer N (> 0) are given. Compute the expression 1 + X/2 − 1·X2/(2·4) + 1·3·X3/(2·4·6) − … + + (−1)N−1·1·3·…·(2·N−3)·XN/(2·4·…·(2·N)). The result is an approximate value of the square root of 1 + X.
For29. An integer N (> 1) and two points A, B (A < B) on the real axis are given. The segment [A, B] is divided into N sub-segments of equal length. Output the length H of each sub-segment and then output the sequence of points A, A + H, A + 2·H, A + 3·H, …, B, which forms a partition of the segment [A, B].
For30. An integer N (> 1) and two points A, B (A < B) on the real axis are given. The segment [A, B] is divided into N sub-segments of equal length. Output the length H of each sub-segment and then output the values of a function F(X) = 1 − sin(X) at points dividing the segment [A, B]: F(A), F(A + H), F(A + 2·H), …, F(B).
For31. An integer N (> 0) is given. A sequence of real numbers AK is defined as: A0 = 2, AK = 2 + 1/AK−1, K = 1, 2, … . Output terms A1, A2, …, AN of the sequence.
For32. An integer N (> 0) is given. A sequence of real numbers AK is defined as: A0 = 1, AK = (AK−1 + 1)/K, K = 1, 2, … . Output terms A1, A2, …, AN of the sequence.
For33°. An integer N (> 0) is given. An integer-valued sequence of the Fibonacci numbers FK is defined as: F1 = 1, F2 = 1, FK = FK−2 + FK−1, K = 3, 4, … . Output terms F1, F2, …, FN of the sequence.
For34. An integer N (> 1) is given. A sequence of real numbers AK is defined as: A1 = 1, A2 = 2, AK = (AK−2 + 2·AK−1)/3, K = 3, 4, … . Output terms A1, A2, …, AN of the sequence.
For35. An integer N (> 2) is given. A sequence of integers AK is defined as: A1 = 1, A2 = 2, A3 = 3, AK = AK−1 + AK−2 − 2·AK−3, K = 4, 5, … . Output terms A1, A2, …, AN of the sequence.
Loop with the parameter: nested loops
For36°. Given positive integers N and K, find the sum 1K + 2K + … + NK. To avoid the integer overflow, compute the sum using real variables and output the result as a real number.
For37. Given an integer N (> 0), find the sum 11 + 22 + … + NN. To avoid the integer overflow, compute the sum using real variables and output the result as a real number.
For38. Given an integer N (> 0), find the sum 1N + 2N−1 + … + N1. To avoid the integer overflow, compute the sum using real variables and output the result as a real number.
For39. Positive integers A and B (A < B) are given. Output all integers in the range A to B, with an integer of a value K being output K times (for example, the number 3 must be output 3 times).
For40. Integers A and B (A < B) are given. Output all integers in the range A to B, with the number A being output once, the number A + 1 being output twice, and so on.
|