You are on page 1of 13
511122, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 Quiz 4 (Jan 12, 2022) FOR Section C Students ONLY Q1. The given function definition takes an array NUM and two Integers n (which denotes the length of the array) and k. The array is assumed to be sorted in ascending order (nums{i] <= numsfj] for all i; while((c <= 123456) && printf("%d", c); + 8) && (c += 2); For the following values of < input_>, what will be the output printed? Write INFINITE_LOOP as the output if the program will not terminate. 7 14 21 42 Max. score: Neg, score: 0; Your score: Your answer: htpsshelaitk.acinvesct01a2122I#hresuv28 ana 5111722, 6:00 PM ESC101/AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 INFINITE_LOOP Feedback: Incorrect answer Q3 You are given the following “incomplete” code. #include int main() { int n; scanf("%d", &n); for (int i=1; i<=2*n-1; i++) { for (int j; j<=n; j++) { if (i<=n) { if (__(a)___<=n) printf( else printf("%d",__(b)__); } else{ printf("9d", __(c)_); + + printf("\n"); } return 0; + You are also given the following three expressions: (1) n-i4j (2) H4j (3) l4}en. Which of the following options map the expressions to their correct positions in the code such that when given the input 4, the code generates the output: htpsshelaitk ac nveset01a2122/#resuv28 23 si11/22, 600M ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 Max. score: 6; Neg. score: U; Your score: 0 {a)-(3), (b)-(2), (c)-(1) {a)-(2), (b)-(4), (€)-(3) {a)-(3), (b)-(4), (c)-{2) {a)-(2), (b)-(3), (c)-(1) Q4A square matrix M with N rows is represented in an array A such that Mfi][j] comes before M[pl[q] in the array if and only ifi < por i= pandj 30 && ((e == f) && d) || (@ = 30) || (b = nrinttiMOnd OLA OLA Oss Obs Oka" a he dw Ae Itpsietoticac ivesc101a2122Mresu28 200)) { ana 11/22, 600 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 Your answer: 40 2050 1913 Feedback: Incorrect answer QB What is the output of the code snippet? int arr] = {1, 4, 8, 3}; int sum = 0; for (int i = 0;i <4; i++) { sum += arrfi]; } intk = 4) int flag for (int i = 3; i >= 0; i-) { if (sum /k < arrfi]) flag = 0; + printf("%d", flag); Max. score: 3; Neg. score: 0; Your score: 0 Your answer: 2 Feedback: Incort answer Q9 Find how many times the do-while loop gets cuted in the following code snippet aH; peers) htpsshelaitk acinveset01a2122/#resuv28 o3 5111722, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 5; Neg. score: 0; Your answer: INFINITE LOOP Feedback: wrong answer Q10 Consider the following cod int a{] = {1,2,3,4,5,6,7,8,9,0} for (int i = 0; i < 10; i++) { if (i < 7 &&i++%3 ali++] = 0; + tow many non-zero elements are there in the array a after executing the snippet? Does the answer change for multiple executions of the for loop on a? Max. score: 6; Neg. score: O; Your score: 0 Your answer: 8 Feedback: Part(a) incorrect Part(b}- not answered Q.11 Consider the following where a, b, ¢ dare integers. What is the value of d? Max. score: 2; Neg, score: 0; Your score: 2 htpsshela tk. acinveset01a2122/#resuv28 ens 511122, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 10 Q412 Consider the following code snippet. int trimulti(int n): 1) return 1; else return trimulti(n-1)*trimulti(n-2)*trimulti(n-3); Answer the following questions based an the cade snippet. (a) Ifn=4 is passed to the function, three different respective return value spaces will be allocated in the stack for the three calls to trimulti(). (b) The stack space required to execute trimulti(3) will be more than the space required for trimulti(2). (c) How many times will trimulti() be reauired to be called if trimulti(4) is calculated? Max. score: 6; Neg. score: 0; Your score: 0 Your answer: Feedback: Q13 Rohit wrote a program to evaluate the value of a mathematical expression. #include #include int funcl(char c) { return (¢ >= '0' && ¢ <= '9'); + int func2(char c) { return (c - ‘1'); } int evaluate(char *eqn) { if (*eqn == '\0') return -1; int val = func2(eqn{0)); htpsshelaitk ac nveset01a2122I#resuv28 m3 5111722, 6:00 PM ESC101/AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 val += func2(opd); else if (opr == '-') val -= func2(opd); else if (opr ) val *= func2(opd); else if (opr == '/') val /= func2(opd); else return -1; + return val; } int main() { char eqn{500]; scanf("%s", eqn); int val = evaluate(eqn); (val == -1) ? printf("%s is Invalid", eqn) : printf("Value of %s is %d", eqn, val); return 0; } However, the code turned out to be wrong. Show the output of the shown code given the inputs given below. Input: 3+7/3+5 Input: 5+4"2/8 Input: 9+6/4°3 Input: 4444 Briefly explain where Rohit went wrong. Note that you do not need to provide the corrected code, just point out the error. The variable “eqn’ is a string, We need pointers when we pass strings into a function, which you will learn later in this course. For now, think of "eqn" and “eqn” as arrays, and that ean|i] gives us the (i+1)-th character, as is usually the case with arrays. ‘Max. score: 10; Neg. score: 0; Your score: O Your answer: Feedback: Q14 Which of the following are valid variable names in C? There can be more than one correct choice. Max. score: 1; Neg, score: 0; Your score: 1 htpsshela tk. acinveset01a2122/#resuv28 ans 5111/22, 500 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 var var&1 Q15 Passing a long value to a function defined as int foo{int a) in the caller program will not give a compilation error. Max. score; 1; Neg. score: Q; Your score: 0 true Q.16 Not passing arguments to a function defined as int foo(int a) in the caller program will give a compilation error. Max. score: 1; Neg. score: Q; Your score: 1 false true Q.47 How should the character array a be initialized so that the output of the given code is CSENTK? #include int main(){ char a[8] = " " char b[8} b[7] = \0 for (int i = 6; i >= 0; i-) { b{6-i] = afi] + + printf("%s", b); return 0; } Max. score: 3; Neg. score: 0: Your score: 0 Your answer: Feedback: htpsshela tk. acinveset01a2122/#resuv28 ons 5.00 PM 101A: FUNDAMENTAL OF COMPUTING int foo(int A[] ,int n) { int poss[n]; (Cuaeecrren eres) poss[i]=0; heed poss[last]=1 (int i=last-1;i>=0;i--) { Gey Ea peers) { Pert A a (int j=it1;5<=i+ALi];j++) nf (poss[j]) poss[i]=1; Tay int main() 55 int A[é] = {3,2,1,0,4,1}; printf(" d", foo(A,6), foo(A+2,4) ,foo(A+4,2)); 10113 5111722, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 leg. score: 0; Your score: 0 bY not add two char Compilation error because you Character not in the English alphabet Another valid character Q.20 Select the correct option about the output of the following snippet, int main() { inti= while(i { if(i == 5) { break; + i+=2; printf("%d",i); + ax. score: 2; Neg. score: 0; Your score: O Compile error Infinite Loop 7 hitpsinelastk.acivese101a2122iMresuv28 na 5111722, 6:00 PM ESC101/AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online: 2 int main(){ int x func(x return 0; + = 1); ‘Max. score: 1; Neg, score: Q; Your score: 0 false true 2 Give the output of the following snippets, or indicate the error with a brief explanation. 3X(d = 2" jprintf("96d 96d %d 9% %d %, Max. score: 3; Neg, score: Q; Your score: 1 Your answer: Error 223446 242462124 Feedback: Part(b) is incorrect, Explanation not provided for part(a) Score: 9.5 htpsshela tk. acinveset01a2122/#resuv28 ra 5111722, 6:00 PM ESC101AA: FUNDAMENTAL OF COMPUTING ESC101AA: FUNDAMENTAL OF COMPUTING Users Online : 2 htpsshela tk. acinveset01a2122/#resuv28 sa

You might also like