CTS Set 2 PDF
CTS Set 2 PDF
CTS Set 2 PDF
1. You are required to fix all logical errors in the given code. You can click on compile and
run anytime to check the compilation/execution status of the program.You canuse printf
to debug your code. The submitted code should be logically/syntatically correct and pass
all testcases. Do not write the main() function as it is not required.
Code Approach: For this question you will need to correct the given implementation.
We do not expect you to modify the approach or incorporate any additional library
methods.
The function multiplyNumber(int a, int b, int c) accepts three integers a, b and c as
inputs. It is supposed to return the multiplicative product of the maximum two of three
input numbers.
The function looks fine but gives a compilation error.
Your task is to fix the program so that it passes all the test cases.
2. You are required to fix all logical errors in the given code. You can click on compile and
run anytime to check the compilation/execution status of the program.You canuse printf
to debug your code. The submitted code should be logically/syntatically correct and pass
all testcases. Do not write the main() function as it is not required.
Code Approach: For this question you will need to correct the given implementation.
We do not expect you to modify the approach or incorporate any additional library
methods.
The function drawPrintPattern(int n) is expected to print the first n (n >= 0) lines of the
pattern shown below.
For example, if n = 3, the pattern should be:
11
1111
111111
The function compiles successfully but fails to print the desired pattern due to logical
errors.
Your task is to debug the program to pass all the test cases.
void drawPattern(int n){
int i,j,print = 1;
for(i = 1;i<=n;i++){
for(j=1;j<=2*i;j++)
printf("%d",print);
printf("\n");
}
}
3. You are required to fix all logical errors in the given code. You can click on compile and
run anytime to check the compilation/execution status of the program.You canuse printf
to debug your code. The submitted code should be logically/syntatically correct and pass
all testcases. Do not write the main() function as it is not required.
Code Approach: For this question you will need to correct the given implementation.
We do not expect you to modify the approach or incorporate any additional library
methods.
The function sameElementCount(int *arr, int len) accepts an integer array arr of
length len as input and returns the number of elements in arr that are even numbers and
equal to the elements to its right.
Note: In an array, element at index i is considered to be on the left of index and to the
right of index i-1. The last element in arr does not have any element next to it, which
makes it incapable to satisfying the second condition and hence should not be counted.
The function compiles fine but fails to return the desired result for some test cases.
Your task is to fix the program so that is passes all the test cases.
5. You are required to fix all logical errors in the given code. You can click on compile and
run anytime to check the compilation/execution status of the program.You canuse printf
to debug your code. The submitted code should be logically/syntatically correct and pass
all testcases. Do not write the main() function as it is not required.
Code Approach: For this question you will need to correct the given implementation.
We do not expect you to modify the approach or incorporate any additional library
methods.
The function countOccurence(int *arr, int len int value) is supposed to return the
count of occurence of a number value in the input array arr of length len(len >= 0)
The functino compiles successfully but fails to return the desired result due to logical
errors.Your task is to debug the program to pass all the test cases.
int countOccurence(int *arr, int len, int value){
int i=0,count=0;
while(i<len){
if(arr[i++] == value)
count+=1;
}
return count;
}