Cognizant Automata Fix Questions & Pattern – Complete Guide
Cognizant’s on-campus recruitment process has evolved, with a new section called Automata Fix being added to their online test. This section focuses on assessing your debugging skills and your ability to fix errors in given programs. If you’re preparing for Cognizant’s recruitment process, here’s what you need to know about the Automata Fix section, its pattern, syllabus, and sample questions.
Automata Fix is a unique assessment introduced by Cognizant to evaluate a candidate’s ability to identify and resolve errors in code. This section specifically tests how well you can:
The best part? You can take this test in several programming languages, making it versatile for programmers with different language preferences.
The Automata Fix section consists of a variety of coding problems designed to assess different aspects of programming. Here’s a breakdown of what to expect:
Here are some sample questions to help you get a feel for the Automata Fix section:
Given Code:
cCopyEditint main() {
int n;
scanf("%d", &n);
unsigned int i = n;
while(i >= 0) {
printf("%d\n", i);
i--;
}
return 0;
}
Input: 4
Output: Infinite loop
Explanation:
The issue here is a logical error. unsigned int
ranges from 0 to 65535, which leads to a cyclic behavior when i--
is used. The loop will never terminate. The corrected code should use int i = n;
instead.
Given Code:
cCopyEditint main() {
long int fact = 1, n, i;
scanf("%d", &n);
for(i = 1; i <= n; i++) {
fact = fact * i;
}
printf("%d", fact);
return 0;
}
Input: 20
Output: -2102132736
Explanation:
The issue here is with the scanf
and printf
format specifiers. Since fact
and n
are declared as long int
, you should use %ld
instead of %d
in both scanf
and printf
.
Given Code:
cCopyEditvoid main() {
int i, j, n;
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
printf("%d", i);
}
printf("\n");
}
}
Input: 3
Output:
CopyEdit111
222
333
Explanation:
This code has a logical error. The inner loop should start from j = i
instead of j = 1
to achieve the desired pattern. The corrected code is:
cCopyEditfor(j = i; j <= n; j++) {
printf("%d", i);
}
Given Code:
cCopyEditint main() {
int num1, num2, num3;
scanf("%d %d %d", &num1, &num2, &num3);
if (num1 > num2) && (num1 > num3) {
printf("%d", num1);
}
elseif(num2 > num3) {
printf("%d", num2);
}
else {
printf("%d", num3);
}
return 0;
}
Explanation:
There are syntax errors in the code. The condition if (num1 > num2) && (num1 > num3)
needs to be corrected to if ((num1 > num2) && (num1 > num3))
, and elseif
should be corrected to else if
.
Given Code:
cCopyEditvoid binarytodecimal(number) {
// Code to convert binary to decimal
}
Correct Code:
cCopyEditvoid binarytodecimal(int number) {
int dval = 0, base = 1, rem;
while (number > 0) {
rem = number % 10;
dval = dval + rem * base;
number = number / 10;
base = base * 2;
}
return dval;
}
Explanation:
This code converts a binary number to decimal by repeatedly extracting each digit and multiplying it by the corresponding power of 2.
To ace the Automata Fix section, practice is key! Familiarize yourself with common syntax errors, logical bugs, and code reuse patterns. Understanding the problem, spotting bugs, and fixing them efficiently will help you stand out.
The Cognizant Automata Fix section is a great opportunity to showcase your debugging and problem-solving skills. By understanding the common patterns in coding errors and practicing with real examples, you’ll be well-prepared to handle the challenges in this section.