Example [4, 7, 1, 2] -> 3 + 6 + 1 = 10
[input] array.integer inputArray
[output] integer sum of absolute differences of consecutive numbers from inputArray
int arraySumAdjacentDifference(std::vector2.Find the area of a rectangle with given sides.inputArray) { int answer = 0; for (int i = 1; i < inputArray.size(); i++) { answer += std::abs(inputArray[i] - inputArray[i - 1]); } return answer; }
Example rectangleArea(2, 3) = 6
[input] integer a positive integer
[input] integer b positive integer [output] integer
int rectangleArea(int a, int b) { int result = a*b; for(int i=0; i < a; i++){ result = a*b; } return result;3.Determine if the given point is inside the given circle. [input] array.integer point array of length 2 representing a point [input] array.integer center array of length 2 representing the center of a circle [input] integer radius radius of the circle [output] boolean true if point is inside the circle centered at center with radius equal to radius or on its border, false otherwise
boolean insidecircle(std::vector4.Given integer n, find n! (factorial of n).point ,std:vector center,int radius){ struct Helper{ int sqr(int value){ return value*value; } }; Helper h; if(h.sqr(point[0]-center[0])+h.sqr(point[1]-center[1])<=h.sqr(radius)){ return true; } return false; }
[input] integer n non-negative integer
[output] integer
int factorial(int n) { if(n==0){ return 1; } return n*factorial(n-1); }
沒有留言:
張貼留言