TCS Command Line Programs
Tcs has been using TCS Command Line Programs to conduct the first round of Placements in Coding Section, TCS Command Line Arguments Programs, TCS C Compiler, Command Line Arguments Questions for TCS.
TCS Command Line Arguments Programs
This article is for TCS based command line Argument based Questions, you will get to know how to understand the the basic program and write it, Command Base Argument Coding for TCS, Command Line Arguments Questions for TCS.
Paid Material
- Command Line Programming Questions Paid Paper (Pro)
- Command Line Programming Questions Paid Paper (Basic)
Free Material
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.
IMP Note – Before going through these questions scroll below and learn command line programming else this will not be useful or click here for command Line Theory
TCS COMMAND LINE ARGUMENTS QUESITONS
- Most asked TCS Coding Programs
- TCS Coding Questions – 1
- TCS Coding Questions – 2
- TCS Command Line Arguments – Fibonacci Series
- TCS Command Line Program to Swap two numbers
- TCS String Reversal Using Command Line Programming (Most Asked – 104 times)
- Greatest of Two Numbers using CLP
- LCM of Two Number using CLP
- Average of Two Numbers
- Sum of Digits of a number
- Binary to Decimal (asked 25 times)
- Decimal to Binary (asked 42 times)
- Factorial of a Number
- Square Root of Prime Number
- Square Root without sqrt.h
- Armstrong Number
- Reverse Digits of a Number
Part 2
- Odd Even Number
- Binary to Octal
- Decimal to Octal
- Check Leap Year
- Area of Circle
- Area of Triangle
- Checking Palindrome (Number)
- Checking Palindrome (String) (asked 91 Times)
- Checking Prime or Not
TCS Command Line Programs – TCS C CODING QUESTIONS
Command Line Arguments Questions for TCS Basics
- Keywords like getc, scanf, getch, getchar etc can not be used.
- Instead we use command line arguments to fetch the values.
Before reading further, I will suggest not to freak out if you don’t understand TCS Command Line Arguments Programs 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 in TCS C Compiler.

Command Line Arguments Questions for TCS
For TCS Command Line Arguments Programs 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 –
int main(){
// some code in Command Line Arguments Questions for TCS C Compiler
}}
However in command line arguments we write like this –
int main(int argc, char *argv[]){
- argc – It is know 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 for TCS C Compiler
- Total Count of number of Arguments.
- 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.
To pass command line arguments, we typically define main() with two arguments : first argument is the number of command line arguments and second is list of command-line arguments.
int main(int argc, char *argv[]) { /* ... */ }
or
int main(int argc, char **argv[]) { /* ... */ }
Quick Facts for TCS Command Line Arguments Programs
argv[0] contains the default value, not the input 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.
}
- 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 Command Line Arguments Programs | No of Times asked in Command Line Coding | Difficulty Level | Importance |
---|---|---|---|
Command Line Program for Binary to Decimal | 25 | High | High |
TCS Command Line Argument for Factorial of a Number | 21 | Medium | Medium |
TCS Command Line Programs Armstrong Number | 18 | Medium | Medium |
To check if Prime number or not | 27 | Low | Medium |
Sum of Digits of a Number | 41 | Medium | Very High |
Command Line Arguments Questions for TCS Rules for Coding Section Steps:
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.
Command Line Arguments Questions for TCS | Frequency of Repetition in TCS Questions | Importance | Difficulty |
---|---|---|---|
String Reversal Using Command Line Programming | 14 | Low | Very High |
Average of two Numbers for TCS | 39 | Medium | Medium |
Finding LCM of two Numbers | 51 | High | Medium |
Finding HCF/GCD Question with CLP | 66 | High | Medium |
We must only print exact output in Command Line Arguments Questions for TCS Procedure –
- 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 maybe ‘failed’.
- They are indicated like private and public test cases. They have not mentioned what is the test case, which is difficult to understand in TCS Command Line Arguments Programs.
Dont 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.
Youtube Video Tutorial for Command Line Arguments Questions for TCS –
FAQ’s
Ques. How much time is sufficient for the preparation of this section?
Ans. We will suggest at least 2 – 3 days should be sufficient to practice for this section for TCS exam.

MyGeekmonkey also has some cool command line programming coding questions asked in TCS check them out here
Most Asked Programs
You can scroll up to go to individual links of other asked programs but we first want you to learn command line programming above in the theory section and then come here to check most asked programs and then finally go to individual links to find other asked programs for command line.
Beware – Most websites are copying PrepInsta’s content/codes etc. Only trust us. If you see our copied content anywhere please contact us on Facebook and help us :).
Greatest Number Code
#include <stdio.h>
int main(int argc, char *argv[])
{
int c[10];
int i,temp,j,greatest;
j = 0;
for(i=1; i<argc; i++)
{
temp = atoi(argv[i]);
c[j] = temp;
j++;
}
greatest = c[0];
for (i = 0; i < 10; i++) {
if (c[i] > greatest) {
greatest = c[i];
}
}
printf("Greatest of ten numbers is %d", greatest);
return 0;
}
Fibonacci Series
#include <stdio.h>
int main(int argc, char *argv[])
{
int n, first = 0, second = 1, next, c;
n = atol(argv[1]);
printf("First %d terms of Fibonacci series are :-\n",n);
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
printf("%d\n",next);
}
return 0;
}
Factorial Code
#include
int main(int argc, char *argv[])
{
int n,i;
unsigned long long factorial = 1;
n = atol(argv[1]);
for(i=1; i<=n; ++i)
{
factorial *= i;
}
printf("Factorial of %d = %llu", n, factorial);
}
Code for String Reversal
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int k;
char temp;
int i,j=0;
int strsize = 0;
for (i=1; i<argc; i++) {
strsize += strlen(argv[i]);
if (argc > i+1)
strsize++;
}
char *cmdstring;
cmdstring = malloc(strsize);
cmdstring[0] = '\0';
for (k=1; k<argc; k++) {
strcat(cmdstring, argv[k]);
if (argc > k+1)
strcat(cmdstring, " ");
}
i = 0;
j = strlen(cmdstring) - 1;
while (i < j) {
temp = cmdstring[i];
cmdstring[i] = cmdstring[j];
cmdstring[j] = temp;
i++;
j--;
}
printf("\nReverse string is :%s", cmdstring);
return(0);
}
Swapping Numbers
#include <stdio.h>
int main(int argc, char *argv[])
{
double firstNumber, secondNumber, temporaryVariable;
firstNumber = atol(argv[1]);
secondNumber = atol(argv[2]);
temporaryVariable = firstNumber;
firstNumber = secondNumber;
secondNumber = temporaryVariable;
printf("\nAfter swapping, firstNumber = %.2lf\n", firstNumber);
printf("After swapping, secondNumber = %.2lf", secondNumber);
return 0;
}
- TCS Coding Questions – 1
- TCS Coding Questions – 2
- TCS Command Line Arguments – Fibonacci Series
- TCS Command Line Program to Swap two numbers
- TCS String Reversal Using Command Line Programming (Most Asked – 104 times)
- Greatest of Two Numbers using CLP
- LCM of Two Number using CLP
- Average of Two Numbers
- Sum of Digits of a number
- Binary to Decimal (asked 25 times)
- Decimal to Binary (asked 42 times)
- Factorial of a Number
- Square Root of Prime Number
- Square Root without sqrt.h
- Armstrong Number
- Reverse Digits of a Number
- Odd Even Number
- Binary to Octal
- Decimal to Octal
- Check Leap Year
- Area of Circle
- Area of Triangle
- Checking Palindrome (Number)
- Checking Palindrome (String) (asked 91 Times)
- Checking Prime or Not
- TCS Coding Questions – 3
- TCS Programming Questions – 4
- TCS Programming Question – 5
- TCS Programming Question – 6
- TCS Command Line Program – 7




