36 36 votes Consider the following C functions. int tob (int b, int* arr) { int i; for (i = 0; b>0; i++) { if (b%2) arr [i] = 1; else arr[i] = 0; b = b/2; } return (i); } int pp(int a, int b) { int arr[20]; int i, tot = 1, ex, len; ex = a; len = tob(b, arr); for (i=0; i<len ; i++) { if (arr[i] ==1) tot = tot * ex; ex= ex*ex; } return (tot) ; } The value returned by $pp(3,4)$ is _______. Algorithms gatecse-2020 numerical-answers identify-function two-marks + – Arjun 20.8k views answer comment Share Follow Print See all 5 Comments 5 5 Comments reply Show 2 previous comments duckduck commented Dec 5, 2025 reply Follow flag silly mistake : when b%2=0 then else part will execute, not if :( 7 7 replyShare DΛΞMON commented Dec 19, 2025 reply Follow flag instead of $return$ $(tot)$ if we write $ return$ $(ex) $ then answer is $6561 $ $ex $$=$$ 81 $$*$ $81$$ =$$ 6561$ 1 1 replyShare Hatim commented Jan 2 reply Follow flag @Lunar..us bro us 1 1 replyShare Please log in or register to add a comment.
Best answer 30 30 votes Answer $: 81$ $pp(3,4)$ $a=3, b=4 , \text{tot} = 1;$ len = tob(4, array) will return 3 with array set as $001$ as array is updated only once when b%2 != 0). The for loop actually iterates $3$ times for $b = 4, b = 2$ and $b=1,$ and only when $b=1,$ arr[i] is updated. Now pp will run for loop 3 times: $\text{arr}[0] = 0.$ So, $\text{ex} = 3\ast 3 = 9$ $\text{arr}[1] = 0.$ So, $\text{ex} = 9\ast 9 = 81$ $\text{arr}[1] = 1.$ So, $\text{tot} = 1\ast 81 = 81$ Prashant. answered Feb 12, 2020 • edited May 30, 2021 by Lakshman Bhaiya Prashant. comment Share Follow See all 5 Comments 5 5 Comments reply Show 2 previous comments satyaAchar commented Jan 19, 2024 reply Follow flag Milan1999 Anju Mehral in tob() : initially i=0; if(4%2) ---→ if(0) so, it execute else statement… a[0] = 0 then b=2, i =1; if(2%2) ---→ if(0) so, it execute else statement… a[1] = 0 then b=1, i=2; if(1%2) ---→ if(1) so, it execute if statement….. a[2] = 1 then b=0, i=3; and for loop break and return(i=3) to the calling function… i.e, len = 3; 2 2 replyShare avanyaokok commented Sep 9, 2025 reply Follow flag if it satifies the 'if' condition, why would it execute the else statement? 0 0 replyShare ayush18288 commented Oct 4, 2025 reply Follow flag @avanyaokok The tob function takes b=4 i = 0:b is 4 (even). arr[0] = 0.b becomes 4 / 2 = 2.i = 1:b is 2 (even). arr[1] = 0.b becomes 2 / 2 = 1.i = 2:b is 1 (odd). arr[2] = 1.b becomes 1 / 2 = 0.The loop terminates as b is now 0. The function returns the final value of i, which is 3Look in the question carefully , that in if condition of tob it is b%2 which will be 0 in case of even and eventually not executing the if condition and jump to else case.Hope it helps !!! 1 1 replyShare Please log in or register to add a comment.
6 6 votes THIS ILLUSTRATION MAY HELP😀 Asim Siddiqui 4 answered Nov 12, 2020 Asim Siddiqui 4 comment Share Follow 0 reply Please log in or register to add a comment.
3 3 votes Answer: 81 Anshul999 answered Feb 12, 2020 Anshul999 comment Share Follow See all 10 Comments 10 10 Comments reply Show 7 previous comments pradhanaditya commented Feb 12, 2020 reply Follow flag @Bhupendra i will be 3 after the last iteration. 0 0 replyShare Bhupendra commented Feb 12, 2020 reply Follow flag rt.. !! thanks 0 0 replyShare Milan1999 commented Oct 19, 2020 reply Follow flag same i also got 27 0 0 replyShare Please log in or register to add a comment.
3 3 votes The function tob(4, arr) sets the initial values of the first three indices of the array as 0, 0, and 1The function returns index 3 after setting these values.In each iteration of the for loop, whenever an array index has a value of 1, the result 3 * 3 (i.e., ex * ex) is multiplied by the variable tot.The final value of tot is returned, which computes the power of 3, specifically 3^4 = 81.In the GATE exam, don't rush to solve programming questions on paper immediately.Take 10-15 seconds to observe the program and understand what is happening before proceeding.After analyzing, solve the problem carefully and double-check your final answer to ensure its correctness.In this case, the program computes 3^4, so the correct answer is 81. advaith_xyz answered Dec 25, 2024 advaith_xyz comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes https://ideone.com/Aedsbd Nadeen shaik answered Sep 4, 2021 Nadeen shaik comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes Tob() - converts b to binary pp (3,4) = 3^4 = 81 Rocky_Laha answered Jan 9 Rocky_Laha comment Share Follow 0 reply Please log in or register to add a comment.