## TCS Programming Questions with Answers

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.

Get all the questions asked Today in TCS here –

TCS Ninja Live Questions Dashboard

### TCS Paid Material –

The below are only available in PDF as of now, the above are accessible as quizzes.

### Free Materials

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

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 <stdio.h>
#include<math.h>

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 <stdio.h>
#include<conio.h>
#include<math.h>
long 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[1000];
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 <stdio.h>
#include<math.h>

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<stdio.h>
int main()
{
int i=3,n;
printf(“enter nth term”);
scanf(“%d”,&n);
int a[n+1];
a[1]=0;
a[2]=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<stdio.h>
#include<stdlib.h>
#include<string.h>
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]=’\$’;
}
}
for(int i=0;i<p2;i++)
{
if(str2[i]!=’a’ && str2[i]!=’e’ && str2[i]!=’i’ && str2[i]!=’o’ && str2[i]!=’u’)
{
str2[i]=’#’;
}
}
for(int i=0;i<p3;i++)
{
str3[i]=str3[i]-32;
}

printf(“\n%s”,str1);
printf(“\n%s”,str2);
printf(“\n%s”,str3);

return 0;

}

Question 7

Link to this code is here

look at the series below: 1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,…..

This series is formed as below: 1.term(1)=1

2.term(2)=2

3.term(N)=term(N-1)+term(N-2)for N>2

Write a program to find the Nth term in this series .the value N is 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 nth term no other characters /strings and messages should be written to STDOUT.

For example if N =15,the value of 15thn term is 987 which is the sum of 13th and 14th terms . You can assume that the value of n will not exceed 30

Ans:

#include <stdio.h>

int main() {

//code int n;

scanf(“%d”, &n);

if(n == 1)

{

printf(“1”);

}

else if(n ==2)

{

printf(“2”);

}

else

{

int t1=1, t2=2, nth_term; for(int i = 3; i <=n; i++)

{

nth_term = t1 + t2; t1 = t2;

t2 = nth_term;

}

printf(“%d”, nth_term);

}

return 0;

}

Question 8

aaaabbBccdee change to a4b2B1c2d1e2

Write code for this in the comment section below –

int main()

{

char a[100];

int i,count=0;

scanf(“%s”,a);

for(i=0;a[i]!=’\0′;i++)

{

count=1;

while(a[i]==a[i+1])

{

i++;

count++;

}

printf(“%c%d”,a[i],count);

}

return 0;

}

Programming Question :replacing multiple occurances of characters by single character and printing in reverse order  if input:aaaaEEeeecccCCCGEExffe then output:efxEGCceEa

### 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

### TCS Coding Questions with Answers

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[0] 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[0] holds the name of the program.
• argv[1] points to the first command line argument and argv[n] points last argument.

### tcs programming questions and Answers

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. What kind of TCS C Programming Questions are asked in the exam?

Ans. Instead of TCS C Programming Questions and Answers they are now using Command Line Programming instead of TCS C Programming Questions.

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