TCS Questions
TCS Questions
TCS Questions
Example
Input : 250617
Output : 3
• Get a number
• If it is not 0, separate last digit and increment
the count
• Then remove the last digit and calculate
• display count
while (num> 0)
{
digit = num % 10;
if (digit % 2 == 1)
nodd++;
else neven++;
num /= 10;
}
printf("%d“, nodd);
}
Focus academy for career enhancement
Question 2
Write a code to check given number is
palindrome or not. Palindrome number is a
number that is equal to it mirror image.
Example
Input: 28582 Output: Yes
Input: 28128 Output: No
Example
Input: 5
Output: 120
int main ()
{
int n = 9;
printf("%d", fib(n));
return 0;
}
return 0;
}
void main()
{
int a,b,c;
if(a>b&&a>c)
if(b>c)
printf(“%d is the second largest no.”, b); if(c>a&&c>b)
else if(b>a)
printf(“%d is the second largest no.”, c); printf(“second largest no. is %d”, b);
else
if(b>a&&b>c) printf(“second largest no. is %d”, a);
if(a>c)
printf(“the second largest no. is % d”, a); }
else
printf(” the second largest no. is %d”, c);
The numbers in the series should be used to create a Pyramid. The base of
the Pyramid will be the widest and will start converging towards the top
where there will only be one element. Each successive layer will have one
number less than that on the layer below it. The width of the Pyramid is
specified by an input parameter N. In other words there will be N numbers on
the bottom layer of the pyramid.
Input Output
00006
2 00028 00066
00006
3 00028 00066
00120 00190 00276
void main()
{
char string[50];
int i, length = 0;
1
222
33333
Focus academy for career enhancement
#include <stdio.h>
int main()
{
int row, c, n, temp;
scanf("%d",&n); // enter the number of rows
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c < temp ; c++ )
{
printf(" ");
}
temp--;
for ( c = 1 ; c <= 2*row - 1 ; c++ )
{
printf(“%d “, row);
}
printf("\n");
} return 0; }
145 = 1!+4!+5!
Input : 145
Output : Yes
Input : 544
Output : No
• Input :
First string : Hello Second string : el
Output : Ho
Input :
Enter array size : 5
Enter 5 array element : 11 13 11 12 13
Original array is : 11 13 11 12 13
Output :
New array is : 11 13 12
Input :
Enter a string: This is a test string
Output :
Reversed String is: gnirts tset a si sihT
Input :
arr[] = {11, 15, 6, 8, 9, 10}, x = 16
6 + 10 = 16.
Output :
True
LISTEN – SILENT
INTEGRAL - TRIANGLE
Input :
1634
Output :
Yes
Output
C
C++
Java
JavaScript
PHP
Perl
Python
R
Ruby
php
Output:
3
Output:
24
3 5
Output:
1010