×
Cart
order

Tcs Coding Questions 2021 (5000+ SAFE)

Problem:
Given a series: 1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, …
Find the nth term (n starting from 1).

Explanation:
Odd positions: powers of 2 → 2^(0), 2^(1), 2^(2)...
Even positions: powers of 3 → 3^(1), 3^(2), 3^(3)...

Solution (Python):

def find_nth_term(n):
    if n % 2 == 0:  # even position
        return 3 ** (n//2 - 1)
    else:           # odd position
        return 2 ** (n//2)

n = int(input()) print(find_nth_term(n)) Tcs Coding Questions 2021

Example:
Input: 5 → Output: 4 (2²)


Problem Statement: Given a number N, calculate the sum of its prime factors. Problem: Given a series: 1, 1, 2, 3,

Input:

Output:

Example:

Input: 12 Output: 5 (Logic: Prime factors of 12 are 2 and 3. Sum = 2 + 3 = 5)

Solution (C):

#include <stdio.h>
int main() 
    int n, i, sum = 0;
    scanf("%d", &n);
// Logic to find prime factors
    for(i = 2; i <= n; i++) 
        // Check if 'i' is a factor
        if(n % i == 0) 
            // Check if 'i' is prime
            int isPrime = 1;
            for(int j = 2; j * j <= i; j++) 
                if(i % j == 0) 
                    isPrime = 0;
                    break;
if(isPrime) 
                sum += i;
printf("%d", sum);
    return 0;

Example: 45 → 45² = 2025 → split 20 + 25 = 45 → Yes.
Concept: Square, convert to string, split, sum, compare. Example: Input: 5 → Output: 4 (2²)

Problem:
Given a series: 1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, …
Find the nth term (n starting from 1).

Explanation:
Odd positions: powers of 2 → 2^(0), 2^(1), 2^(2)...
Even positions: powers of 3 → 3^(1), 3^(2), 3^(3)...

Solution (Python):

def find_nth_term(n):
    if n % 2 == 0:  # even position
        return 3 ** (n//2 - 1)
    else:           # odd position
        return 2 ** (n//2)

n = int(input()) print(find_nth_term(n))

Example:
Input: 5 → Output: 4 (2²)


Problem Statement: Given a number N, calculate the sum of its prime factors.

Input:

Output:

Example:

Input: 12 Output: 5 (Logic: Prime factors of 12 are 2 and 3. Sum = 2 + 3 = 5)

Solution (C):

#include <stdio.h>
int main() 
    int n, i, sum = 0;
    scanf("%d", &n);
// Logic to find prime factors
    for(i = 2; i <= n; i++) 
        // Check if 'i' is a factor
        if(n % i == 0) 
            // Check if 'i' is prime
            int isPrime = 1;
            for(int j = 2; j * j <= i; j++) 
                if(i % j == 0) 
                    isPrime = 0;
                    break;
if(isPrime) 
                sum += i;
printf("%d", sum);
    return 0;

Example: 45 → 45² = 2025 → split 20 + 25 = 45 → Yes.
Concept: Square, convert to string, split, sum, compare.