Q301
Open questionSelect an option to see the answer and solution.
Practice every MCQ with options. Use Show answers when you want the correct option and solution.
1,171
Questions
16/59
Page
Pick an option on a question to see the right answer and solution.
Q301
Open questionSelect an option to see the answer and solution.
Q302
Open questionSelect an option to see the answer and solution.
Q303
Open questionSelect an option to see the answer and solution.
Q304
Open questionSelect an option to see the answer and solution.
Q305
Open questionSelect an option to see the answer and solution.
Q306
Open questionSelect an option to see the answer and solution.
Q307
Open questionSelect an option to see the answer and solution.
Q308
Open questionvoid 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;
}Select an option to see the answer and solution.
Q309
Open questionSelect an option to see the answer and solution.
Q310
Open question#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;
}Select an option to see the answer and solution.
Q311
Open questionSelect an option to see the answer and solution.
Q312
Open questionSelect an option to see the answer and solution.
Q313
Open question#include<stdio.h>
int recursive_sum(int n)
{
if(n == 0)
return 0;
return n + recursive_sum(n - 1);
}
int main()
{
int n = 5;
int ans = recursive_sum(n);
printf("%d",ans);
return 0;
}
Which of the following is the base case for the above recursive code?Select an option to see the answer and solution.
Q314
Open questionSelect an option to see the answer and solution.
Q315
Open question#include <stdio.h>
#include <stdlib.h>
void combination(int arr[], int aux[], int start, int end, int index, int r);
int compare (const void * a, const void * b)
{ return ( *(int*)a - *(int*)b ); }
void print(int arr[], int n, int r)
{
int aux[r];
qsort (arr, n, sizeof(int), compare);
combination(arr, aux, 0, n-1, 0, r);
}
void combination(int arr[], int aux[], int start, int end, int index, int r)
{
if (index == r)
{
for (int i=0; i<r; i++)
printf("%d " ,aux[i]);
printf(", ");
return;
}
for (int i=start; i<=end && end-i+1 >= r-index; i++)
{
aux[index] = arr[i];
combination(arr, aux, i+1, end, index+1, r);
while (arr[i] == arr[i+1])
i++;
}
}
int main()
{
int arr[] = {1, 2, 2};
int r = 2;
int n = sizeof(arr)/sizeof(arr[0]);
print(arr, n, r);
}Select an option to see the answer and solution.
Q316
Open questionSelect an option to see the answer and solution.
Q317
Open questionint xpowy(int x, int n)
if (n==0) return 1;
if (n==1) return x;
if ((n % 2) == 0)
return xpowy(x*x, n/2);
else
return xpowy(x*x, n/2) * x;Select an option to see the answer and solution.
Q318
Open questionSelect an option to see the answer and solution.
Q319
Open question#include <bits/stdc++.h>
using namespace std;
void convert(int arr[], int n)
{
int temp[n];
memcpy(temp, arr, n*sizeof(int));
sort(temp, temp + n);
unordered_map<int, int> map;
int sort_index = 0;
for (int i = 0; i < n; i++)
map[temp[i]] = sort_index++;
for (int i = 0; i < n; i++)
arr[i] = map[arr[i]];
}
void printArr(int arr[], int n)
{
for (int i=0; i<n; i++)
cout << arr[i] << " ";
}
int main()
{
int arr[] = {3,5,2,4};
int n = sizeof(arr)/sizeof(arr[0]);
convert(arr , n);
printArr(arr, n);
return 0;
}Select an option to see the answer and solution.
Q320
Open questionSelect an option to see the answer and solution.