Miscellaneous On Data Structures - Study Mode
[#1041] What will be the output of the following code? #include<iostream>
using namespace std
int list[200]
void func(int n, int m = 0)
{
int i
if(n == 0)
{
for(i = 0
i < m
++i)
printf("%d ", list[i])
printf("
")
return
}
for(i = n
i > 0
--i)
{
if(m == 0 || i <= list[m - 1])
{
list[m] = i
func(n - i, m + 1)
}
}
}
int main()
{
int n=3
func(n,0)
return 0
}
Correct Answer
(A) 3
2 1
1 1 1
[#1042] How many times will the function fibo() be called when the following code is executed? int fibo(int n)
{
if(n == 1)
return 0
else if(n == 2)
return 1
return fibo(n - 1) + fibo(n - 2)
}
int main()
{
int n = 5
int ans = fibo(n)
printf("%d",ans)
return 0
}
Correct Answer
(D) 9
[#1043] Which cipher is represented by the following function? public class Cipher
{
public static String encrypt(String text, final String key)
{
String res = ""
text = text.toUpperCase()
for (int i = 0, j = 0
i < text.length()
i++)
{
char c = text.charAt(i)
if (c < 'A' || c > 'Z')
continue
res += (char) ((c + key.charAt(j) - 2 * 'A') % 26 + 'A')
j = ++j % key.length()
}
return res
}
Correct Answer
(A) vigenere cipher
(E) vigenere cipher
[#1044] What is the output of the following code? #include<stdio.h>
#include<stdlib.h>
struct Node
{
int val
struct Node* next
}*head
int get_max()
{
struct Node* temp = head->next
int max_num = temp->val
while(temp != 0)
{
if(temp->val > max_num)
max_num = temp->val
temp = temp->next
}
return max_num
}
int get_min()
{
struct Node* temp = head->next
int min_num = temp->val
while(temp != 0)
{
if(temp->val < min_num)
min_num = temp->val
temp = temp->next
}
return min_num
}
int main()
{
int i, n = 9, arr[9] ={8,3,3,4,5,2,5,6,7}
struct Node *temp, *newNode
head = (struct Node*)malloc(sizeof(struct Node))
head -> next =0
temp = head
for(i=0
i<n
i++)
{
newNode =(struct Node*)malloc(sizeof(struct Node))
newNode->next = 0
newNode->val = arr[i]
temp->next =newNode
temp = temp->next
}
int max_num = get_max()
int min_num = get_min()
printf("%d %d",max_num,min_num)
return 0
}
Correct Answer
(D) 8 2
[#1045] What is the output of the following code? void my_recursive_function(int n)
{
if(n == 0)
return
printf("%d ",n)
my_recursive_function(n-1)
}
int main()
{
my_recursive_function(10)
return 0
}
Correct Answer
(D) 10 9 8 ... 1