Home / MCQ Bank / Computer
Computer Blocks And Procs In Ruby Difficulty: Medium

How do you create a proc in Ruby?

Select the correct option to test your answer:

More Computer Questions

What will be the output of the following C# code snippet? class access { public int x; private int y; public void cal(int a, int b) { x = a + 1; y = b; } public void print() { Console.WriteLine(" " + y); } } class Program { static void Main(string[] args) { access obj = new access(); obj.cal(2, 3); Console.WriteLine(obj.x); obj.print(); Console.ReadLine(); } } Consider the following dynamic programming implementation of the matrix chain problem: #include<stdio.h> #include<limits.h> int mat_chain_multiplication(int *mat, int n) { int arr[n][n]; int i,k,row,col,len; for(i=1;i<n;i++) arr[i][i] = 0; for(len = 2; len < n; len++) { for(row = 1; row <= n - len + 1; row++) { col = row + len - 1; arr[row][col] = INT_MAX; for(k = row; k <= col - 1; k++) { int tmp = ________________________; if(tmp < arr[row][col]) arr[row][col] = tmp; } } } return arr[1][n - 1]; } int main() { int mat[6] = {20,5,30,10,40}; int ans = mat_chain_multiplication(mat,5); printf("%d",ans); return 0; } Which of the following lines should be inserted to complete the above code? Which of the following functions return absolute value of a variable? Assume +, -, *, / are usual arithmetic operator, + has highest precedence and right associative and -, *, / have equal precedence and left associative. What is the output of the expression 23 * 3 - 6 + 11 - 2 * 8 / 4? Consider the following implementation of Kadane's algorithm: #include<stdio.h> int max_num(int a, int b) { if(a > b) return a; return b; } int kadane_algo(int *arr, int len) { int ans = 0, sum = 0, idx; for(idx =0; idx < len; idx++) { sum = max_num(0,sum + arr[idx]); ans = max_num(sum,ans); } return ans; } int main() { int arr[] = {-2, -3, -3, -1, -2, -1, -5, -3},len = 8; int ans = kadane_algo(arr,len); printf("%d",ans); return 0; } What changes should be made to the Kadane's algorithm so that it produces the right output even when all array elements are negative? Change 1 = Line 10: int sum = arr[0], ans = arr[0] Change 2 = Line 13: sum = max_num(arr[idx],sum+arr[idx])