Sie sind auf Seite 1von 12

CODING QUESTIONS – TCS NQT

BASIC PROBLEMS
• PATTERNS
• NUMBERS AND SERIES
• BASIC STRING OPERATIONS
PATTERN PRINTING

1 1 * 54321 54321
22 12 ** 4321 5432
333 123 *** 321 543
4444 1234 **** 21 54
55555 12345 ***** 1 5
PATTERN PRINTING

1 1 12345677654321
12 21 123456 654321
123 321 12345 45321
1234 4321 1234 4321
12345 54321 123 321
123456 654321 12 21
12345677654321 1 1
PATTERN PRINTING
12345677654321 * *
123456 654321 * ** **
12345 45321
1234 4321 ** ***
****
***
****
123 321
12 21
*** ***** *****
****** ******
1
1 1
1
**** ******* *******
****** ******
12
123
21
321
***** ***** *****
1234
12345
4321
54321
****** ****
***
****
***
123456 654321 ******* ** **
12345677654321 * *
NUMBERS AND SERIES
• Check whether a number is prime number or not
• Sample input: Enter a number: 8
• Sample Output: Not Prime
• Sample input 2: Enter a number: 13
• Sample output 2: Prime

• Check whether a number is prime-palindrome or not


• Sample input: Enter a number: 13
• Sample Output: Prime, Not palindrome
• Sample input 2: Enter a number: 101
• Sample output 2: Prime Palindrome
• Sample input 3: Enter a number: 2112
• Sample output3: Palindrome, Not Prime.
NUMBERS AND SERIES
• Check whether a number is Perfect number or not
• Sample input: Enter a number: 6
• Sample Output: Perfect number
• Sample input 2: Enter a number: 495
• Sample output 2: Not Perfect

• Check whether a number is armstrong or not.


• Sample input: Enter a number: 153
• Sample Output: Armstrong Number
• Sample input 2: Enter a number: 101
• Sample output 2: Not Armstrong
NUMBERS AND SERIES
• Print Fibonacci series up to a number n along with their sum.
• Sample input: Enter a number m : 10
Enter a number n : 20
• Sample Output: 11,13,17,19

• Print Fibonacci series up to a number n along with their sum. Also print the number of
odd and even numbers in the series and their sums separately.
• Sample input: Enter a number n: 20
• Sample Output: 0,1,1,2,3,5,8,13
Sum: 33
Number of odd: 5
Number of even: 2
Sum of odd: 23
Sum of even: 10
NUMBERS AND SERIES

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 fail 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 in a positive integer that should be read from mm. The Nth term that is calculated by the program should
be written to STDOUT Other than the value of Nth term , no other characters / string 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
NUMBERS AND SERIES
A Pythagorean triplet is a set of three integers a, b and c
such that a2 + b2 = c2. Given a limit, generate all Pythagorean
Triples with values smaller than given limit.

Input : limit = 20
Output :
3 4 5
8 6 10
5 12 13
15 8 17
12 16 20
NUMBER CONVERSION
Given a decimal number as input, we need to write a program to convert the
given decimal number into equivalent octal number. i.e convert the number
with base value 10 to base value 8. The base value of a number system
determines the number of digits used to represent a numeric value. For
example, the binary number system uses two digits 0 and 1, octal number
system uses 8 digits from 0-7 and decimal number system uses 10 digits 0-9
to represent any numeric value.

Examples:

Input : 16

Output : 20

Input : 10

Output : 12

Input: 33

Output: 41
NUMBER CONVERSION
• Decimal to Octal

• Octal to Binary

• Decimal to Binary

• Binary to decimal

Das könnte Ihnen auch gefallen