Cognizant Automata Fix questions | Cognizant Automata Fix pattern

Cognizant has updated its pattern recently. Cognizant Automata Fix is a section in the cognizant on-campus recruitment process. Since Cognizant conducts its online test using AMCAT platform, Amcat Automata fix questions will be asked in this new section. This article provides more details about Automata Fix pattern, sylabus and sample questions.

What is Cognizant Automata Fix?

  • Automata Fix is the new assessment that cognizant has included as part of its online test. It checks the candidate’s computer programmer’s ability to debug an erroneous code and fix it.
  • The test provides a set of programs to the candidate, where they have to either debug them or right new functionality based on the given functions and code.
  • It tests the candidate’s skill of being able to understand code written by someone else, be able to find bugs and also use the code to implement new functionality. This assessment is available across multiple programming languages.

Cognizant Automata Fix Questions Pattern

Type of questionDescription
LogicalThe candidate is required to fix all logical errors in the given code.
CompilationCandidate needs to correct the syntax of the given code without changing its logic.
Code ReuseCandidates need to compare the given code by reusing existing functions.

Questions of Automata Fix may come from the below concepts. Also, the difficulty level of sections is given below.

  • Logical questions: This checks the various logical concepts like Conditions, looping etc.
  • Compilation questions: This checks the candidate basic knowledge of syntax and language-specific concepts.
  • Code Reuse questions: This is a bit tougher than the logical and compilation based questions. The candidate is required to complete the code using the predefined structure or functions.

 

Cognizant Automata Fix Questions with Solutions

1) Check for syntax error/ logical error and correct the error to get the desired output.

Given n, print from n to 0

int 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

Answer: Error  – Logical error
unsigned int i = n; unsigned integer ranges from 0 to 65535, which will be taken in the cyclic order. So i– will keep repeating in a cyclic way. The loop will never be terminated. So it should be written as int i = n; 

2) Find the factorial of a given number.

int 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

Answer: Error – Logical error
The fact and n are declared as long int, so in scanf and printf %ld should be used in place of %d.

3) Check whether the below program print the below pattern
1111
222
33

void 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:
111
222
333

Answer: Error: Logical error
The inner for loop has to be written in this way:  for(j = i-1; j<n; j++)
 

4) Find the greatest of three numbers.

int 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;
}

Answer: Error: Syntax error
if (num1 > num2) && (num1 > num3) à it has to be written as if ((num1 > num2) && (num1 > num3)) and  this line elseif(num2>num3)  should be rewritten as else if(num2>num3) 

5) Fix the error, recompile and match against the output provided.

int main(void)
{
printf("This is a \"buggy" program\n");
    return 0;
}

Corrected program:
int main(void)
{
    printf(“This is a \”buggy\” program\n”);
    return 0;
}

6) Code reuse: Convert Binary to Decimal by using the existing function.

void  binarytodecimal(number)
{
              // Type your code here
}
void main()
{
    int num;
    scanf("%d", &num);
    printf(“%d”, binarytodecimal(num);
}

Answer:

void  binarytodecimal(number)
{
  int dval=0, base=1, rem;
  while(number > 0)
  {
              rem = number % 10;
              dval = dval + rem * base;
                  num = number / 10;
                  base = base * 2;
  }
  return dval;
}

7) Print the prime numbers from an array up to given value n by using existing function.

int isprime(int num)
{
// type your code here 
}
int main()
{
int n, m, arr[100], size=0, i;
scanf("%d", &n);
for(m = 2; m <= n; m++)
{
if(isprime(m))
{
    arr[size++]= m;
}
}
for(i = 0; i < size; i++)
{
printf("%d\n", arr[i]);
}
return 0;
}

Answer:

int isprime(int num)

  int i;
  int isprime = 1;
  for(i = 2;  i <= num / 2; i++) 
  {      
           if(num % i == 0)      
           {            
                        isprime = 0;         
                              break;    
           }
   }   
   return isprime;
 }

11 thoughts on “Cognizant Automata Fix questions | Cognizant Automata Fix pattern”

  1. hi there…, Dis is Rafi Pinjari pursuing MCA final year in CBIT, Hyderabad, Telangana. At my college, I’m going to attend Cognizant campus drive i.e 08/09/2018. I need your help in cracking automata fix section. I prepared TCS ninja in our portal, whatever the questions you gave are just awesome. So I’m expecting your help to crack Cognizant pls send updates and information about cognizant as soon as possible.

  2. hi ..,iam girija pursuing my engg in psnacet, dindugul , Tamilnadu .i’m going to attend cognizant camous drive on 14/09/2018.i need ur help in automata fix.iam expecting your help by updating info about cognizant as soon as possible.

    1. Hi girija,
      Mostly automata fix contain debugging questions and to write program with functions(methods ) whose functionality will be mentioned.
      Do post about your interview details once you attend

  3. Hii… Face prep team and a lot of greetings. Actually I need your help to crack the Automata Fix because the Cognizant campus derive is coming at my college. As I prepared for Tcs ninja from your team. So I want your help. Please

Leave a Reply