 TCS Programming Test Questions are not like a general Coding Round Questions with Solutions it is all together different from C programming. We have analysed over 100+ TCS Programming Questions they use Command Line Programming in the Programming Section of the test. Below you will find TCS Programming Round Questions, TCS Coding Questions that are asked constantly in TCS Placement Papers Programming, programming Test of TCS Placement Coding Questions, TCS C Coding Questions, TCS C Programming Questions, TCS Coding Section, TCS C Programming Questions and Answers.

Important Note : TCS has just introduced new test pattern for 2020 Batch pass-outs students. The pattern for 2019 pass-outs being the same. Below are the tables with detailed analysis on the same. Make sure you do not refer any other paper pattern as below one is the most updated paper pattern for both 2019 and 2020 Passouts.

For 2020 Passouts :

• No Of Questions:- 1 Question
• Time – 30 mins

For 2019 Passouts :

• No Of Questions:- 1 Question
• Time – 20 mins

Get all the questions asked Today in TCS here –

TCS Ninja Live Questions Dashboard

TCS Placement Papers Programming Online Classes

1. Free Paid Materials also given

TCS Paid Material –

In Online class you will get preparation paid materials access also, but if you just want materials then you can buy the ones below –

or

Prices increase for Paid materials in

Minutes
Seconds

Free Materials

Checking if a given year is leap year or not

``````#include <stdio.h>

int main()
{
int year;

printf("Enter a year: ");
scanf("%d",&year);

if(year%4 == 0)
{
if( year%100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year%400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
}
else
printf("%d is a leap year.", year );
}
else
printf("%d is not a leap year.", year);

return 0;
}``````
``````#include <iostream>
using namespace std;

int main()
{
int year;

cout << "Enter a year: ";
cin >> year;

if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
cout << year << " is a leap year.";
else
cout << year << " is not a leap year.";
}
else
cout << year << " is a leap year.";
}
else
cout << year << " is not a leap year.";

return 0;
}``````
``````public class LeapYear {

public static void main(String[] args) {

int year = 1900;
boolean leap = false;

if(year % 4 == 0)
{
if( year % 100 == 0)
{
// year is divisible by 400, hence the year is a leap year
if ( year % 400 == 0)
leap = true;
else
leap = false;
}
else
leap = true;
}
else
leap = false;

if(leap)
System.out.println(year + " is a leap year.");
else
System.out.println(year + " is not a leap year.");
}
}``````

Question

Ques. Write a code to check whether no is prime or not. Condition use function check() to find whether entered no is positive or negative ,if negative then enter the no, And if yes pas no as a parameter to prime() and check whether no is prime or not?

`#include<stdio.h>void primeno(int n);void main(){int n;printf("Pleaseenter no\n");scanf("%d",&n);if(n<0){printf("Please enter a positive integer");}elseprimeno(n);}void primeno(int n){int c=0;for(int i=2;i<n;i++){if(n%i==0)++c;}if(c>=1)printf("Entered number is not a prime number");elseprintf("Entered number is a prime number");}`
`import java.util.Scanner;class CheckPrime{public static void main(String[] args){System.out.println("Enter the number to be checked");Scanner sc=new Scanner(System.in);int n=sc.nextInt();CheckPrime ob=new CheckPrime();ob.check(n);}void check(int n){if(n<0)System.out.println("Please enter a positive integer");elseprime(n);}void prime(int n){int c=0;for(int i=2;i<n;i++){if(n%i==0)++c;}if(c>=1)System.out.println("Entered number is not a prime number");elseSystem.out.println("Entered number is a prime number");}}`

Question

1. Using a method, pass two variables and find the sum of two numbers.

Test case:

Number 1 – 20

Number 2 – 20.38

Sum = 40.38

There were a total of 4 test cases. Once you compile 3 of them will be shown to you and 1 will be a hidden one. You have to display error message if numbers are not numeric.

CORRECT CODE –

#include
#includeint main()
{
int x;float y;

scanf(“%d%f”,&x,&y);
if(isnan(x) || isnan(y)){
printf(“Error”);
}else
printf(“%0.2f”,(float)x+y);
return 0;
}

Question 0

Find the 15th term of the series?

0,0,7,6,14,12,21,18, 28

Question 1

Find the nth term of the series.

1,1,2,3,4,9,8,27,16,81,32,243,….

#include
#include
int three(n)
{
int x,i;
for(i=0;i<100;i++)
{
x=pow(3,i);
if(i==n)
printf(“%d”,x);
}
}
int two(n)
{
int x,i;
for(i=0;i<100;i++)
{
x=pow(2,i);
if(i==n)
printf(“%d”,x);
}
}
int main()
{
int n;
scanf(“%d”,&n);
if(n%2==0)
three(n/2);
else
two(n/2+1);
}

Question – 2

Consider the following series: 1,1,2,3,4,9,8,27,16,81,32,243,64,729,128,2187…

This series is a mixture of 2 series – all the odd terms in this series form a geometric series and all the even terms form yet another geometric series. Write a program to find the Nth term in the series.

The value N in a positive integer that should be read from STDIN. The Nth term that is calculated by the program should be written to STDOUT. Other than value of n th term,no other character / string or message should be written to STDOUT. For example , if N=16, the 16th term in the series is 2187, so only value 2187 should be printed to STDOUT.

You can assume that N will not exceed 30.

#include
#include

int main() {
//code
int n;
scanf(“%d”, &n);
if(n % 2 == 1)
{
int a = 1;
int r = 2;
int term_in_series = (n+1)/2;
int res = pow(2, term_in_series – 1);
printf(“%d “, res);
}
else
{
int a = 1;
int r = 3;
int term_in_series = n/2;
int res = pow(3, term_in_series – 1);
printf(“%d “, res);
}

return 0;
}

Extra Questions without Solutions and Options that students couldn’t remember, please add solutions in the comment section below –

1. Given a series whose even term creates a separate geometric series and odd term creates another geometric series . Prog in any language to find the nth term. Where u may consider that n not greater dan 30.
2. 1,1,2,2,4,4,8,8,16,16 also this code

Solutions to one of the problem discussed above –

#include
#include
#includelong long int power(long long int a,long long int b ){

long long int i,ans=1;
for(i=0;i<b;i++)
{
ans=ans*a;
}
return ans;
}

// long long int three(long long int n){
// return pow(3,n);
// }

// long long int two(long long int n){

// return pow(2,n);
// }

int main()
{
clrscr();
long long int i,nth,a;
scanf(“%lld”,&nth);
for(i=0;i<nth;i++)
{
if(i%2==0)
{
a[i]=power(2,i/2);
}
if(i%2==1)
{

a[i]=power(3,(i/2)+1);
}

}

printf(“%lld “,a[nth-1]);

return 0;
}

Question 3

Consider the below series :

0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8

This series is a mixture of 2 series all the odd terms in this series form even numbers in ascending order and every even terms is derived from the previous  term using the formula (x/2)

Write a program to find the nth term in this series.

The value n in a positive integer that should be read from STDIN the nth term that is calculated by the program should be written to STDOUT. Other than the value of the nth term no other characters /strings or message should be written to STDOUT.

For example if n=10,the 10 th term in the series is to be derived from the 9th term in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be printed to STDOUT.

You can assume that the n will not exceed 20,000.

Code:

#include
#include

int main() {
//code
int n;
scanf(“%d”, &n);
if(n % 2 == 1)
{
int a = 1;
int r = 2;
int term_in_series = (n+1)/2;
int res = 2 * (term_in_series – 1);
printf(“%d “, res);
}
else
{
int a = 1;
int r = 3;
int term_in_series = n/2;

int res = term_in_series – 1;
printf(“%d “, res);
}

return 0;
}

Question 4

0,0,2,1,4,2,6,3,8,4,10,5,12,6….

#include
int main()
{
int i=3,n;
printf(“enter nth term”);
scanf(“%d”,&n);
int a[n+1];
a=0;
a=0;
while(i<=n)
{
if(i%2==0)
a[i]=a[i-2]+1;
else
a[i]=a[i-2]+2;
i++;
}
printf(“%d”,a[n]);
}

Question 5

1. The program will recieve 3 English words inputs from STDIN

1. These three words will be read one at a time, in three separate line
2. The first word should be changed like all vowels should be replaced by \$
3. The second word should be changed like all consonants should be replaced by #
4. The third word should be changed like all char should be converted to upper case
5. Then concatenate the three words and print them

Other than these concatenated word, no other characters/string should or message should be written to STDOUT

For example if you print how are you then output should be h\$wa#eYOU.

You can assume that input of each word will not exceed more than 5 chars

Write Code for this

#include
#include
#include
int main()
{
char *str1=malloc(sizeof(char)*256);
char *str2=malloc(sizeof(char)*256);
char *str3=malloc(sizeof(char)*256);
printf(“ENter 3 words : “);
scanf(“%s%s%s”,str1,str2,str3);

int p1=strlen(str1);
int p2=strlen(str2);
int p3=strlen(str3);
for(int i=0;i<p1;i++)
{
if(str1[i]==’a’||str1[i]==’e’||str1[i]==’i’||str1[i]==’o’||str1[i]==’u’)
{
str1[i]=’

Free Materials

We have a lots of free materials don’t worry. Check them out below.

TCS Coding Section used to be based on Command Line Argument based Coding Questions it is available no where else on the internet. We will try help you with learning command line argument based coding for TCS.

From this year there is no command Line programming but you have to use C, C++, Java, Python and Perl. We have the latest set of questions for the new pattern

Question 0

Find the nth term of the series.

1,1,2,3,4,9,8,27,16,81,32,243,….

`#include<stdio.h>#include<math.h>int three(n){int x,i;for(i=0;i<100;i++){x=pow(3,i);if(i==n)printf("%d",x);}}int two(n){int x,i;for(i=0;i<100;i++){x=pow(2,i);if(i==n)printf("%d",x);}}int main(){int n;scanf("%d",&n);if(n%2==0)three(n/2);else two(n/2+1);}`

TCS Coding Questions and Solutions

Languages allowed –

1. C
2. C++
3. Command Line in C
4. Java
5. Perl
6. Python

Platform will be eclipse based compiler. You can code on onlinegdb.com. All your codes working on this website would run perfectly in TCS compiler.

Non Command Line Programs

Command Line Programs (Not in Syllabus anymore

TCS Coding Round Questions in Test Pattern and Syllabus

• Number of Questions – 1
• Total time to Solve – 20 mins
• Difficulty Level – 1 Easy Questions
• Cut-off – Solve 1 question completely or partial output

Though command Line Programming is not there you should study it for C MCQ section as 1-2 MCQ would be there for command Line program.

TCS C Programming Questions Basics

• Keywords like getc, scanf, getch, getchar etc can not be used.
• Instead we use command line arguments to fetch values.

TCS Coding Section

Before reading further for TCS Coding Round Questions, I will suggest not to freak out if you don’t understand in first go. Read everything once and then when you read again things will start to make sense. It is the best resource on the internet to know about TCS command line Argument Type Questions and TCS C Programming Questions and Answers.

TCS Programming Test Facts and Questions

TCS coding test based facts and tricks, TCS Programming Questions, TCS Programming Test –

TCS Coding Round Questions TopicsDifficulty in TCS Coding RoundProbability of asking in TCS Coding TestTime to solve
LCM HCF TCS Coding QuestionsMedium1020 mins
Swapping and Reversal TCS Coding Round QuestionsHard2020 mins
Factorial and SeriesMedium2020 mins
Operations on Numbers in TCS Coding TestEasy3020 mins
MiscMedium – Hard2020 mins

Let us consider this, if you wanted to write a basic C program then you would’ve written a main function that would’ve looked like in compiler for TCS Coding Round Questions –

int Main(){

// some code

}}

tcs placement coding questions

However in command line arguments we write like this –

int main(int argc, char *argv[]){

• argc – It is known as Argument Count and as clear from the name it stores the Count of number of Arguments.
• argv[] – Pointer, contains location of all the values(arguments).
• *argv[] – Array of values of all the arguments.
• They are parameters/arguments supplied to the program when it is invoked.

Thus, now we have two things

1. Total Count of number of Arguments.
2. All the values/pointer location of arguments stored in an array.

Now, you will need one more thing i.e. atoi();

• atoi(); – Converts string into int and atoi(argv[i]); will give the value of argument at ith location in int type format.

Now you can use an int val = atoi(argv[i]); to store the value and then print it with printf(); function.

Check out this video Below to learn how to Solve Command Line Programming.

Quick Facts

argv contains the name, not the value so –

• All for loops must start from i=1.
• You must use the following condition

if(argc == 1){

// do nothing since, there are no arguments, maybe ask for arguments?

}else{

// code to apply logic and print values in TCS Coding Round Questions.

}

• provided+1 +1 for file.exe
• argv[argc] is a NULL pointer.
• argv holds the name of the program.
• argv points to the first command line argument and argv[n] points last argument.

TCS Programming Questions with Answers TypeNo of times asked in TCS Programming TestImportance for Programming RoundDifficulty in TCS C Programming Questions
TCS C Programming Questions on String Reversal14LowVery High
Average of two Numbers39MediumMedium
TCS Placement Papers Programming LCM of two Numbers51HighMedium
HCF/GCD Question66HighMedium
Command Line Arguments here – Read this properly.

`// Program to print all value of// command line argument// once we get the value from command// line we can use them to solve our problem.#include  // this is used to print the result using printf#include  // this is used for function atoi() for converting string into int`

// argc tells the number of arguments
// char *argv[] is used to store the command line
arguments in the pointer to char array i.e string format
int main(int argc, char *argv[])
{
// means only one argument exist that is file.exe
if (argc == 1) {
printf(“No command line argument exist Please provide them first \n”);
return 0;
} else {
int i;
// actual arguments starts from index 1 to (argc-1)
for (i = 1; i < argc; i++) {
int value = atoi(argv[i]);
// print value using stdio.h library’s printf() function
printf(“%d\n”, value);
}
return 0;
}
}

` `

TCS Programming Test Based FAQ’s

Ques. What is the level of difficulty of the question asked in TCS programming round?

Ans. They are easy but you need to have good grip over basic C/C++ input/output or pattern based programs.

Logics like Recursion, For loops, If loops etc

Ques. What languages can we use in TCS Coding Round Questions?

Ans. In TCS Coding Round Questions currently you can only use C/C++ and Java for coding in TCS based Compiler that is mostly GCC type of compiler.

Ques. Is PrepInsta enough to prepare for TCS Coding Round and Questions asked in the exams?

Ans. Yes, it is the best resource out there in the internet to prepare for TCS Coding section paper.

Rules for TCS Coding Round Questions Section:

There is only one question for 20 minutes.
• It has 10 attempts(We can compile only 10 times).
• We must start our code from the scratch.
• The coding platform is divided into two, one for writing the code and other for output. We should write the whole
program.
• We can’t use any input functions like scanf(), getch(), getchar().
• The input to be provided should be read as command line arguments.

We must only print exact output.
• Output must not be re-framed by extra words.
• If there is any error, the error will be shown in the output dialog box.
• The errors are clearly mentioned.
• If there are no errors, a message like “compiled successfully” will be printed.
• Along with that they will mention four test cases are ‘passed’ or ‘failed’. They are indicated like private and public test cases. They have not mentioned what is the test case, which is difficult to understand.

Don’t Compile again and again since compiler takes 25 seconds and each time you compile 25 seconds will become lesser in the time you have to code in TCS Placement Papers Programming.

Ques. How to clear the TCS coding round?

Ans. First you must learn command line programming from our coding dashboard and then try sample questions given on the dashboard to know how to clear the tcs coding round  and TCS C Programming Questions and Answers

Ques. What are some other websites where we can find more questions?

Ans. You can find more questions on MyGeekMonkey website here – http://mygeekmonkey.com/tcs-coding-questions.html

Summary
Review Date
Reviewed Item
TCS Coding Questions
Author Rating
5     