TCS Interview Experience | Set 15 – New 2017 Pattern
In TCS 2017 campus placement, first round has introduced new pattern. This year onward, the test shall consist of 4 sections, instead of the earlier two. The duration, however, shall remain the same, i.e. 90 minutes. The details are:
1. Verbal Test (10 Mins) : This shall be similar to previous year’s section.
2. Quantitative Test (40 Mins) : This section will have only 20 questions now.
3. Test on Programming Language Proficiency (20 Mins) : This section shall have MCQ based questions related to basic programming concepts (on C language).
4. Coding Test (20 Mins) : This section shall require the student to solve a coding problem real time using an in built compiler (on C Language).
To solve this 4th section you can’t use keywords like “scanf, getc, getch, getchar” so to solve this type of coding problem. You have to use input from command line arguments.
Sample Program to Print all Command Line argument integers
#include <stdio.h> // this is used to print the result using printf
#include <stdlib.h> // this is used for function atoi() for converting string into int
provided+1 +1 for file.exe
arguments in the pointer to char array i.e string format
int main( int argc, char *argv[])
{
if (argc == 1) {
printf ( "No command line argument exist Please provide them first \n" );
return 0;
} else {
int i;
for (i = 1; i < argc; i++) {
int value = atoi (argv[i]);
printf ( "%d\n" , value);
}
return 0;
}
}
|
Output:
24
50
If command line arguments will be 24 50.
Here is another sample question for this type of questions.
Problem Statement : Write a C program to calculate the factorial of a non negative integer N. The factorial of a number N is defined as the product of all integers from 1 up to N. Factorial of 0 is defined to be 1. The number N is a non negative integer that will be passed to the program as the first command line parameter. Write the output to stdout formatted as an integer WITHOUT any other additional text. You may assume that the input integer will be such that the output will not exceed the largest possible integer that can be stored in an int type variable.
Example:
If the argument is 4, the value of N is 4.
So, 4 factorial is 1*2*3*4 = 24.
Output : 24
#include <stdio.h> // for printf
#include <stdlib.h> // for function atoi() for converting string into int
int fact( int n)
{
if (n == 0)
return 1;
else {
int ans = 1;
int i;
for (i = 1; i <= n; i++) {
ans = ans * i;
}
return ans;
}
}
int main( int argc, char * argv[])
{
if (argc == 1) {
printf ( "No command line argument exist Please provide them first \n" );
return 0;
} else {
int i, n, ans;
for (i = 1; i < argc; i++) {
n = atoi (argv[i]);
ans = fact(n);
printf ( "%d\n" , ans);
}
return 0;
}
}
|
Output:
24 if command line argument is 4.
In this, the programs asked in the exam are of moderate difficulty if you practice college’s first year C syllabus you should get good marks. Programs like Area of a circle, reversing a string, palindromes are asked.
Last Updated :
12 Sep, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...