Cognizant Coding Syllabus 2019 (Updated) : Type of Question Description
Cognizant Coding Syllabus 2019 (Updated) : Type of Question Description
Cognizant Coding Syllabus 2019 (Updated) : Type of Question Description
Aptitude(Quant) 25 min 25
Logical 35 min 25
Verbal 20 min 22
In CTS test, 7 Automata fix questions (5 debugging & 2 partial code) are to be answered in 20
minutes.
A set of programs will be given, where students have to either debug erroneous code and fix
it or write 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.
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
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++)
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;
}