Hi friends, today in this post we’ll see the latest cognizant coding questions with answers. If you want to land your dream job in Congnizant but don’t know where to get started. Then you’re at the right place, here we’ll provide you with the latest cognizant coding questions with answers. But before getting started we’ll give you some little information about Cognizant. So,

Table of Contents

## What is Cognizant?

Cognizant is an American multinational IT company that provides information technology services as well as consultancy services. It was founded by Kumar Mahadeva and Francisco D’Souza in the year 1994. Its headquarters are situated in Teaneck, New Jersey.

Cognizant is also part of NASDAQ-100 which trades under CTSH. They started serving their clients in the year 1996. This company is ranked 185th in the world. It also comes in the top 10 list of MNC companies in India.

Each year Cognizant conducts on-campus as well as off-campus drives in which they hire thousands of employees. Their DCs are situated in every part of our country.

Now we’ll see the exact cognizant coding questions asked each year.

## Cognizant Coding Questions

From this year the cognizant have changed their exam pattern. The written test is divided into two rounds which are:

- 1st Round (Aptitude + Automata Fix)
- 2nd Round (Coding Round)

In this section, we’ll mainly focus on only cognizant coding questions. The details are given in the following table:

Topics | Details |
---|---|

Total No of Questions | 4 |

Time Limit | 40 + 80 minutes |

Level of Difficulty | Medium |

Package Offered | Nearly About 6 LPA |

## Preparation Section for Cognizant Coding Round

If you want to crack the coding round conducted by Cognizant then you’ve to do more and more practice based on the following topics:

## Cognizant Coding Questions With Answers

Here we’ve mentioned all the questions which are asked previously by Cognizant. If you practice these questions then you might be able to solve Cognizant coding questions. So let’s see the questions one by one.

### Cognizant Coding Question 1

**Q. Find the LCM of Two given numbers?**

In this question you’ve to accept two numbers from the user for which you’ve to find the LCM of the given numbers. The LCM stands for Lowest Common Factor which is the smallest number that divides both the given numbers.

**Sample Input 1:**

5 10

**Sample Output 1:**

10

**Sample Input 2:**

20 60

**Sample Output 2:**

60

**Program:**

//Learnprogramo - programming made simple #include<iostream> using namespace std; int HCF(int, int); int LCM(int, int); int main() { int num1, num2, result; cout<<"Enter two numbers\n"; cin>>num1; cin>>num2; result = LCM ( num1, num2 ); cout<<endl<<"The output is\n"; cout<< result; return 0; } // This function find the Highest Common Factor of the two numbers int HCF (int num1, int num2) { if (num2 == 0) return num1; return HCF(num2, num1 % num2); } // This function find the Lowest Common Factor of the two numbers int LCM (int num1, int num2) { return (num1 * num2) / HCF(num1, num2); }

**Output:**

### Cognizant Coding Question 2

**Q. Shraddha Kapoor’s professor suggested her study hard and prepare well for the lesson on seasons. If her professor says month then, she has to tell the name of the season corresponding to that month. So write the program to get the solution to the above task?**

- March to May – Spring Season
- June to August – Summer Season
- September to November – Autumn Season
- December to February – Winter Season

**Note:** The entered month should be in the range of 1 to 12. If the user enters a month less than 1 or greater than 12 then the message “Invalid Month Entered” should get displayed.

**Sample Input 1:**

Enter month: 6

**Sample Output 1:**

Season: Summer

**Sample Input 2:**

Enter month: 15

**Sample Output 2:**

Invalid Month Entered

**Program:**

//Learnprogramo - programming made simple #include<stdio.h> #include <stdlib.h> int main () { printf ("Enter the month:\n"); int entry; scanf ("%d", &entry); switch (entry) { case 12: case 1: case 2: printf ("Season: Winter"); break; case 3: case 4: case 5: printf ("Season: Spring"); break; case 6: case 7: case 8: printf ("Season: Summer"); break; case 9: case 10: case 11: printf ("Season: Autumn"); break; default: printf ("Invalid month Entered"); } return 0; }

**Output:**

### Cognizant Coding Question 3

**Q. In the nearby theater, one scheme is announced that one purchase of the ticket will get a total of 10% discount on the total cost of tickets. This scheme will be applicable only if there is a bulk booking of more than 20 tickets. If someone has a special coupon card then a 2% discount will be given on the total cost. The customer can also purchase some refreshments at the additional cost of 50 Rs per person.**

**The ticket cost for the B class is 75 Rs and that of class A is 150 Rs. So Write a program to calculate the total cost as per the given scheme?**

**Note:** In class A and class B, you’ve to purchase a minimum of 5 tickets and a maximum of 40 tickets. If this condition gets failed then the message should be displayed as “Minimum 5 and a maximum of 40 tickets should be purchased”.

**Sample Input 1:**

Enter no of Tickets: 35

Do you want to purchase any refreshments: y

Do you have any coupon code: y

Enter the circle: B

**Sample Output 1:**

Total Ticket Cost: 4065.25

**Sample Input 2:**

Enter no of Tickets: 1

**Sample Output 2:**

Minimum 5 and a maximum of 40 tickets should be purchased

**Program:**

//Learnprogramo - programming made simple #include<stdio.h> #include <stdlib.h> int main() { int noTicket; double total = 0,cost; char ref[2], co[2] , circle[2]; printf("Enter no of Tickets:"); scanf("%d",&noTicket); if (noTicket < 5 || noTicket > 40) { printf("Minimum 5 and a maximum of 40 tickets should be purchased"); exit(0); } printf("Do you want to purchase any refreshments:"); scanf("%s",&ref); printf("Do you have any coupon code:"); scanf("%s",&co); printf("Enter the circle:"); scanf("%s",&circle); if(circle[0] == 'B') cost=75*noTicket; else if(circle[0]== 'A') cost=150*noTicket; else { printf("Invalid Input"); exit(0); } total=cost; if(noTicket>20) cost= cost - ((0.1)*cost); total=cost; if(co[0]== 'y') total= cost - ((0.02)*cost); if(ref[0]== 'y') total += (noTicket*50); printf("Total Ticket cost:%.2f",total); return 0; }

**Output:**

### Cognizant Coding Question 4

**Q. Write a program to print the prime number series from 1 to N where N is an input?**

**Sample Input 1:**

15

**Sample Output 1:**

2 3 5 7 11 13

**Sample Input 2:**

5

**Sample Output 2:**

2 3 5

**Program:**

//Learnprogramo - programming made simple #include<iostream> using namespace std; bool isPrime (int); int main () { int n; cout<<"Enter the Number:\n"; cin >> n; for (int i = 1; i <= n; i++) { int isPrimeNumber = isPrime (i); if (isPrimeNumber == true) { cout << i << "\t"; } } return 0; } // This function is identifying the number is prime or not bool isPrime (int n) { bool flag = false; for (int i = 2; i <= n / 2; i++) { if (n % i == 0) { flag = true; break; } } if (flag == false && n > 1) { // Number is prime return true; } // Number is not a prime return false; }

**Output:**

### Cognizant Coding Question 5

**Q. Sanjana teaches her daughter how to find the factors of a given number. But when She provides a number to her daughter then the daughter should tell all the factors of that number correctly. So help Sanjana’s daughter by writing a program?**

**Note:** If the entered input is zero then the output should be “No Factors”. And if the entered input is a negative number then first convert it to positive and then find its factors.

**Sample Input 1:**

Enter the positive integer: 55

**Sample Output 1:**

Factors of 55 are: 1 5 11 55

**Sample Input 1:**

Enter the positive integer-256

**Sample Output 2:**

Factors of 256 are: 1 2 4 8 16 32 64 128 256

**Program:**

//Learnprogramo - programming made simple #include <iostream> #include <cstdlib> using namespace std; int main () { int n, i; cout << "Enter the positive integer: "; cin >> n; if (n == 0) { cout << "No Factors"; return false; } if (n < 0) { n = abs (n); } cout << "Factors of " << n << " are: "; for (i = 1; i <= n; ++i) { if (n % i == 0) { cout << i<<"\t"; } } return 0; }

**Output:**

### Cognizant Coding Question 6

Q. Darshan went to a movie with his fellow friends in a nearby theatre and during the half break, he purchased some pizzas, puffs, and cold drinks. Now consider the given prices:

**100 Rs / Pizza****20 Rs / Puffs****10 Rs / Cold drink**

**Write a program to generate the final bill so that darshan can pay?**

**Sample Input 1:**

Enter the number of pizzas purchased: 10

The number of puffs purchased: 12

Enter the no of Cold Drinks purchased: 5

**Sample Output 1:**

Bill Details:

No of Pizzas: 10

The No of Puffs: 12

No of Cold drinks: 5

Total Price=1290

Enjoy the Show!!!

**Program:**

//Learnprogramo - programming made simple #include<stdio.h> #include <stdlib.h> int main () { int totalprice; printf ("Enter the no of pizzas bought:\n"); int pizza; scanf ("%d", &pizza); printf ("Enter the no of puffs bought:\n"); int puffs; scanf ("%d", &puffs); printf ("Enter the no of cool drinks bought:\n"); int coolDrinks; scanf ("%d", &coolDrinks); int pizzaa = pizza * 100; int puffss = (puffs) * 20; int coolDrinkss = (coolDrinks) * 10; printf ("Bill Details\n"); printf ("No of pizzas: %d\n", pizza); printf ("No of puffs: %d\n", puffs); printf ("No of cooldrinks: %d\n", coolDrinks); totalprice = pizzaa + puffss + coolDrinkss; printf ("Total price= %d\n", totalprice); printf ("ENJOY THE SHOW!!!"); return 0; }

**Output:**

### Cognizant Coding Question 7

**Q. Shambhu wants the magic board, which will display a character for the corresponding number in his science project. Now help him to develop such an application?**

**For Example:** when the digits like 65, 66, 67, 68 are entered then the alphabet A B C and D will be displayed. Assume the no of inputs should be always 4

**Sample Input 1:**

Enter the digits:

65 66 67 68

**Sample Output 1:**

65-A 66-B 67-C 68-D

**Sample Input 2:**

Enter the digits:

115 116 101 112

**Sample Output 2:**

115-s 116-t 101-e 112-p

**Program:**

//Learnprogramo - programming made simple #include<stdio.h> #include <stdlib.h> int main () { printf ("Enter the digits: \n"); int a, b, c, d; scanf ("%d%d%d%d", &a, &b, &c, &d); char q = (char) a; char w = (char) b; char e = (char) c; char r = (char) d; printf ("%d - %c\n", a, q); printf ("%d - %c\n", b, w); printf ("%d - %c\n", c, e); printf ("%d - %c\n", d, r); return 0; }

**Output:**

### Cognizant Coding Question 8

**Q. To speed up the composition of generating the unpredictable rhythms, The green bandits want the lists of all the prime numbers available in the range of numbers. Help him out?**

**Write a C program to print all the prime numbers in the given interval [a,b] in which a and b both are inclusive?**

**Note:** The 1st input should be smaller than the 2nd input. Both the inputs should be positive. The range should be always greater than the zero. The “Provide valid input” message should be get displayed if any of the conditions fail. Use minimum 1 for and while loop.

**Sample Input 1:**

2 15

**Sample Output 1:**

2 3 5 7 11 13

**Sample Input 1:**

8 5

**Sample Output 2:**

Provide Valid Input

**Program:**

//Learnprogramo - progrmaming made simple #include<stdio.h> #include <stdlib.h> int main () { int a, b; scanf ("%d%d", &a, &b); int flag; if (a <= 0 || b <= 0 || a >= b) printf ("Provide valid input"); else { while (a <= b) { if (a == 2) printf ("%d ", a); else if (a == 1) { a++; continue; } else { flag = 0; for (int i = 2; i <= a / 2; i++) { if (a % i == 0) { flag = 1; break; } } if (flag == 0) printf ("%d ", a); } a++; } } return 0; }

**Output:**

### Cognizant Coding Question 9

**Q. Every day Jaydeep and Sanjana play by telling some numbers to each other. Jaydeep says a number to Sanjana. Sanjana should first reverse the number and then check if it’s the same as the original number or not. Sanjana should say “Palindrome” if it’s the same otherwise “Not Palindrome”. And if the number is negative then print “Invalid Input”. Now help Sanjana by writing a program?**

**Sample Input 1:**

121

**Sample Output 1:**

**Sample Input 2:**

4785

**Sample Output 2:**

Not a Palindrome

**Program:**

//Learnprogramo - programming made simple #include<stdio.h> #include <stdlib.h> int main () { int n; scanf ("%d", &n); int sum = 0, r; int temp = n; if (n > -1) { while (n > 0) { r = n % 10; sum = (sum * 10) + r; n = n / 10; } if (temp == sum) printf ("Palindrome"); else printf ("Not a Palindrome"); } else { printf ("Invalid Input"); } return 0; }

**Output:**

### Cognizant Coding Question 10

**Q. Jaideep planned to choose a four-digit number for his new car. The numbers 3, 5, and 7 are Jaideep’s favorites. Now help Jaideep to find the number, whose sum is divisible by the numbers 3, 5, and 7. Provide a valid number of cars. If the input provided is not valid then display the message “Not a valid car number”?**

**Note:** The entered input should be only 4 digit positive numbers. If the input is negative or less than 1 the input is invalid.

**Sample Input 1:**

Enter the car no: 1234

**Sample Output 1:**

Lucky Number

**Sample Input 2:**

Enter the car no: 1214

**Sample Output 2:**

Sorry, it’s not my lucky number.

**Sample Input 3:**

Enter the car no: 15

**Sample Output 3:**

15 is not a valid car number

**Program:**

//Learnprogramo - programming made simple #include<bits/stdc++.h> using namespace std; int main () { int n; cin >> n; int digit = floor (log10 (n) + 1); if (n <= 0 or ! (digit == 4)) cout << n << " is not a valid car number"; else { int sum = 0; while (n > 0) { sum += n % 10; n /= 10; } if (sum % 3 == 0 or sum % 5 == 0 or sum % 7 == 0) cout << "Lucky Number"; else cout << "Sorry its not my lucky number"; } return 0; }

**Output:**

## Conclusion

In this way, we’ve seen all the main cognizant coding questions with answers asked in the previous years. If you’ve any doubts then please feel free to contact us. We’ll reply as soon as possible.

Thanks and Happy Coding :)

**Also Read:**

- Amcat Coding Questions.
- Mindtree Coding Questions.
- Cocubes Test.
- TCS Codevita.
- Zoho Aptitude Questions.
- Wipro Coding Questions.
- Hexaware Interview Questions.
- Accenture Coding Questions.
- Capgemini Exam Pattern.