Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
69 views8 pages

TCS Looping Practice

The document outlines a series of programming questions and problems related to matrices, cost estimation, series calculations, and number theory. Each question provides specific input and output requirements, including examples for clarity. The problems range from finding maximum values in a matrix to calculating terms in various mathematical series.

Uploaded by

vaishnahegde41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views8 pages

TCS Looping Practice

The document outlines a series of programming questions and problems related to matrices, cost estimation, series calculations, and number theory. Each question provides specific input and output requirements, including examples for clarity. The problems range from finding maximum values in a matrix to calculating terms in various mathematical series.

Uploaded by

vaishnahegde41
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Question 1

A parking lot in a mall has RxC number of parking spaces. Each parking space will
either be empty(0) or full(1). The status (0/1) of a parking space is represented as
the element of the matrix. The task is to find index of the prpeinzta row(R) in the
parking lot that has the most of the parking spaces full(1).

Note :
RxC- Size of the matrix
Elements of the matrix M should be only 0 or 1.

Example 1:
Input :
3 -> Value of R(row)
3 -> value of C(column)
[0 1 0 1 1 0 1 1 1] -> Elements of the array M[R][C] where each element is
separated by new line.
Output :
3 -> Row 3 has maximum number of 1’s

Example 2:
input :
4 -> Value of R(row)
3 -> Value of C(column)
[0 1 0 1 1 0 1 0 1 1 1 1] -> Elements of the array M[R][C]
Output :
4 -> Row 4 has maximum number of 1’s

Question 2
Problem Statement

We want to estimate the cost of painting a property. Interior wall painting cost
is Rs.18 per sq.ft. and exterior wall painting cost is Rs.12 per sq.ft.

Take input as
1. Number of Interior walls
2. Number of Exterior walls
3. Surface Area of each Interior 4. Wall in units of square feet
Surface Area of each Exterior Wall in units of square feet

If a user enters zero as the number of walls then skip Surface area values as
User may don’t want to paint that wall.

Calculate and display the total cost of painting the property


Example 1:

6
3
12.3
15.2
12.3
15.2
12.3
15.2
10.10
10.10
10.00
Total estimated Cost : 1847.4 INR

Note: Follow in input and output format as given in above example

Question3
There are total n number of Monkeys sitting on the branches of a huge Tree. As
travelers offer Bananas and Peanuts, the Monkeys jump down the Tree. If every
Monkey can eat k Bananas and j Peanuts. If total m number of Bananas and p
number of Peanuts are offered by travelers, calculate how many Monkeys remain
on the Tree after some of them jumped down to eat.
At a time one Monkeys gets down and finishes eating and go to the other side of
the road. The Monkey who climbed down does not climb up again after eating
until the other Monkeys finish eating.
Monkey can either eat k Bananas or j Peanuts. If for last Monkey there are less
than k Bananas left on the ground or less than j Peanuts left on the ground, only
that Monkey can eat Bananas(<k) along with the Peanuts(<j).
Write code to take inputs as n, m, p, k, j and return the number of Monkeys left
on the Tree.
Where, n= Total no of Monkeys
k= Number of eatable Bananas by Single Monkey (Monkey that jumped down
last may get less than k Bananas)
j = Number of eatable Peanuts by single Monkey(Monkey that jumped down
last may get less than j Peanuts)
m = Total number of Bananas
p = Total number of Peanuts
Remember that the Monkeys always eat Bananas and Peanuts, so there is no
possibility of k and j having a value zero

Example 1:
Input Values
20
2
3
12
12

Output Values
Number of Monkeys left on the tree:10

Note: Kindly follow the order of inputs as n,k,j,m,p as given in the above
example. And output must include the same format as in above
example(Number of Monkeys left on the Tree:)
For any wrong input display INVALID INPUT

Question 4
Find the 15th term of the series?

0,0,7,6,14,12,21,18, 28

Explanation : In this series the odd term is increment of 7 {0, 7, 14, 21, 28, 35 – –
––––}

And even term is a increment of 6 {0, 6, 12, 18, 24, 30 – – – – – – }


Question 5
Consider the following series: 1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243, 64, 729, 128,
2187 …

This series is a mixture of 2 series – all the odd terms in this series form a
geometric series and all the even terms form yet another geometric series. Write
a program to find the Nth term in the series.

The value N in 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 value
of n th term,no other character / string or message should be written to
STDOUT. For example , if N=16, the 16th term in the series is 2187, so only value
2187 should be printed to STDOUT.

You can assume that N will not exceed 30.

Question 6
Consider the below series :

0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8

This series is a mixture of 2 series all the odd terms in this series form even
numbers in ascending order and every even terms is derived from the previous
term using the formula (x/2)

Write a program to find the nth term in this series.

The value n in 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 the nth term no other characters /strings or message should be written to
STDOUT.

For example if n=10,the 10 th term in the series is to be derived from the 9th term
in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4
should be printed to STDOUT.

You can assume that the n will not exceed 20,000.


Question 7
Consider the below series :

0, 0, 2, 1, 4, 2, 6, 3, 8, 4, 10, 5, 12, 6, 14, 7, 16, 8

This series is a mixture of 2 series all the odd terms in this series form even
numbers in ascending order and every even terms is derived from the previous
term using the formula (x/2)

Write a program to find the nth term in this series.

The value n in 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 the nth term no other characters /strings or message should be written to
STDOUT.

For example if n=10,the 10 th term in the series is to be derived from the 9th term
in the series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4
should be printed to STDOUT.

You can assume that the n will not exceed 20,000.

Question 8
Oddly Even Problem Statement
Given a maximum of 100 digit numbers as input, find the difference between the
sum of odd and even position digits

Test Cases

Case 1

• Input: 4567
• Expected Output: 2
Explanation : Odd positions are 4 and 6 as they are pos: 1 and pos: 3, both have
sum 10. Similarly, 5 and 7 are at even positions pos: 2 and pos: 4 with sum 12.
Thus, difference is 12 – 10 = 2

Case 2

• Input: 5476
• Expected Output: 2

Case 3

• Input: 9834698765123
• Expected Output: 1

Question 9
Question. Find the nth term of the series.

1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243,64, 729, 128, 2187 ….

This series is a mixture of 2 series – all the odd terms in this series form a
geometric series and all the even terms form yet another geometric series. Write
a program to find the Nth term in the series.

• The value N in 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 value of n th term,no other character / string or message should
be written to STDOUT.
• For example , if N=16, the 16th term in the series is 2187, so only value
2187 should be printed to STDOUT.

You can assume that N will not exceed 30.

Test Case 1

• Input- 16
• Expected Output – 2187

Test Case 2

• Input- 13
• Expected Output – 64

Explanation
1, 1, 2, 3, 4, 9, 8, 27, 16, 81, 32, 243,64, 729, 128, 2187 can represented as :

• 2(0), 3(0),2(1), 3(1),2(2), 3(2),2(3), 3(3),2(4), 3(4),2(5), 3(5),2(6), 3(6) ….

There are two consecutive sub GP’s at even and odd positions

• (GP-1) At Odd Positions (Powers of 2) – 1, 2, 4, 8, 16, 32, 64, 128


• (GP-2) At Even Positions (Powers of 3) – 1, 3, 9, 27, 81, 243, 729, 2187

Clearly, for calculating Nth position value

• If N is Even, Find (N/2) position in sub GP – 2


• If N is Odd, Find (N/2 + 1) position in sub GP – 1

Question 10
Consider the below series :

0,0,2,1,4,2,6,3,8,4,10,5,12,6,14,7,16,8

• This series is a mixture of 2 series all the odd terms in this series form even
numbers in ascending order
• Every even terms is derived from the previous term using the formula (x/2)

Write a program to find the nth term in this series.

1. The value n in a positive integer that should be read from STDIN the nth
term that is calculated by the program should be written to STDOUT.
2. Other than the value of the nth term no other characters /strings or
message should be written to STDOUT.

For example

if n=10,the 10 th term in the series is to be derived from the 9th term in the
series. The 9th term is 8 so the 10th term is (8/2)=4. Only the value 4 should be
printed to STDOUT.

You can assume that the n will not exceed 20,000.

Question 11
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 Otherthan 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

Question 12
Write a C program to check whether the given number is a perfect square or not
using command line arguments.

You might also like