On this page, you can practice with TCS Ninja Coding Questions or important programming logic questions. It will be helpful for getting placement in IT Company easily.

## TCS Ninja Coding Questions

Hey guys, as we have already discussed **TCS Ninja Hiring** in detail in our other post. You can check it out on the link. So here in this article, we will be giving you some **important Coding questions from TCS Ninja Hiring Process**. **TCS Ninja** completes their hiring process in 3 levels and among these 3 levels, the 1st one is a test in which you will be asked coding questions.

So here we are discussing some questions to help you with this. Make sure you read this article till the end. We assure you that we have gathered these questions from our own authentic questions.

**Important coding questions from TCS Ninja hiring**

**Question 1**. Nth Fibonacci Number using Command Line Arguments

**Answer 1.** #include

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

{

int num,i,fact=1;

num=atoi(argv[1]);

for(i=1;i<=num;i++)

{

fact=fact*i;

}

printf(“Factorial of the number is %d”,fact);

}

Also Check:TCS Imp Aptitude Questions

**Question 2**. Consider the below series:

1, 2, 1, 3, 2, 5, 3, 7, 5, 11, 8, 13, 13, 17, …

This series is a mixture of 2 series – all the odd terms in this series form a Fibonacci series and all the even terms are the prime numbers in ascending order.

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 or message should be written to STDOUT.

For example, when N = 14, the 14th term in the series is 17. So only the value 17 should be printed to STDOUT.

**Answer 2.** #include

#define MAX 1000

void fibonacci(int n)

{

int i, t1 = 0, t2 = 1, nextTerm;

for (i = 1; i<=n; i++)

{

nextTerm = t1 + t2;

t1 = t2;

t2 = nextTerm;

}

printf(“%d”, t1);

}

void prime(int n)

{

int i, j, flag, count =0;

for (i=2; i<=MAX; i++)

{

flag = 0;

for (j=2; j<i; j++)

{

if(i%j == 0)

{

flag = 1;

break;

}

}

if (flag == 0)

if(++count == n)

{

printf(“%d”, i);

break;

}

}

}

int main()

{

int n;

scanf(“%d”, &n);

if(n%2 == 1)

fibonacci (n/2 + 1);

else

prime(n/2);

return 0;

}

**Question 3.** Write a C program to find the area of a circle with the radius provided.

The value of the radius positive integer passed to the program as the first command line parameter. Write the output to stdout formatted as a floating point number rounded to EXACTLY 2 decimal precision WITHOUT any other additional text.

Scientific format(such as 1.00E+5) should NOT be used while printing the output.

You may assume that the inputs will be such that the output will not exceed the largest possible real number that can be stored in a float type variable.

**Answer 3.** #include

#include

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

{

if(argc==1)

{

printf(“No arguments”);

return 0;

}

else

{

int radius;

float pi=3.14;

float area;

radius=atoi(argv[1]);

area=pi*radius*radius;

printf(“%.2f”,area);

return 0;

}

}

**Question 4.** Given a series whose even term creates a separate geometric series and odd term creates another geometric series. Write a program to generate such a series.

For example,

1, 1, 2, 2, 4, 4, 8, 8, 16, 16,……

**Answer 4.** #include

int main()

{

int n, i, r1, r2;

printf(“\nEnter the total number of terms : “);

scanf(“%d”, &n);

printf(“\nEnter the common ratio for GP – 1 : “);

scanf(“%d”, &r1);

printf(“\nEnter the common ratio for GP – 2 : “);

scanf(“%d”, &r2);

printf(“\nThe series is\n”);

int a = 1, b = 1;

if(n % 2 == 0)

{

for(i = 0; i < n/2; i++)

{

printf(“%d “, a);

a = a * r1;

printf(“%d “, b);

b = b * r2;

}

}

else

{

for(i = 0; i < n/2; i++)

{

printf(“%d “, a);

a = a * r1;

printf(“%d “, b);

b = b * r2;

}

printf(“%d “, a);

}

printf(“\n”);

}

**Question 5.** Command Line Program to check if a year is Leap Year or Not

**Answer 5.** #include

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

{

int n;

n=atoi(argv[1]);

if(n%4==0)

{

if(n%100==0)

{

if(n%400==0)

printf(“Leap Year”);

else

printf(“Not Leap Year”);

}

else

printf(“Leap Year”);

}

else

printf(“Not Leap Year”);

getch();

}

Check Here:How To Crack Email Writing Round

**Question 6.** Command Line Program to Convert Decimal to Octal.

**Answer 6.** #include

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

{

int n,s=0,b=1,r;

n=atoi(argv[1]);

int c=n;

while(c>0)

{

r=c%8;

s=s+r*b;

c=c/8;

b=b*10;

}

printf(“%d”,s);

getch();

}

**Question 7.** The square root of a Prime number by checking first if it is a prime number?

Write a C program that will check whether a given number N is a Prime or Not. If the Number N is a Prime, then find it’s square root and print that value to the STDOUT as floating point number with exactly 2 decimal precision.

If the number is not Prime, then print the value 0.00 to STDOUT.

The given number will be positive non zero integers and it will be passed to the program as the first command line argument.

Other than floating point No other information should be printed to STDOUT.

**Answer 7.** [code language=”cpp”]

#include

#include

#include

#include

bool isPrime(int n)

{

if(n<2)

return false;

int i;

for(i=2;i*i<=n;i++)

{

if(n%i==0)

return false;

}

return true;

}

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

{

if(argc==1)

{

printf(“No arguments”);

return 0;

}

else

{

int n;

n=atoi(argv[1]);

float sq=0;

if(isPrime(n))

{

sq=sqrt(n);

printf(“%.2f”,sq);

}

else

printf(“%.2f”,sq);

return 0;

}

}

[/code]

**Question 8.** Write a C program that will calculate the square root of a number without using math.h sqrt() function and print that sqrt to the STDOUT as floating point number with exactly 2 decimal precision.

**Answer 8.** [code language=”cpp”]

#include

#include

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

{

if(argc==1)

{

printf(“No arguments”);

return 0;

}

else

{

int n;

n=atoi(argv[1]);

float i=0.00;

while(i*i<=n)

{

i=i+0.001;

}

i=i-0.001;

printf(“%.2f”,i);

}

}

[/code]

**Question 9.** Command Line Program to find Area of Triangle.

**Answer 9.** #include

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

{

int base, height;

float area;

base = atol(argv[1]);

height = atol(argv[2]);

area = base*height/2;

printf(“%f”,area);

}

**Question 10.** Command Line Program for Odd-Even.

**Answer 10.** #include

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

{

int number;

number = atol(argv[1]);

if(number % 2 == 0)

printf(“%d is even.”, number);

else

printf(“%d is odd.”, number);

return 0;

}

#### TCS Directory

TCS Next Steps Registration – Apply Here |

TCS Ninja Hiring – Register Here |

TCS ION CCQT – Check Details |

TCS Ignite 2019 Registration |

TCS Eligibility Criteria – Read Here |

So, guys, these were 10 important questions. We have collected these from reliable sources. So guys if you have any queries then you can comment us below and if you guys need any other help then you can also contact us. We will be happy to help you with all your queries. Do comments for review.