0% found this document useful (0 votes)
49 views

Internal Programming Training Questions

Java Practice queation

Uploaded by

Santhose
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Internal Programming Training Questions

Java Practice queation

Uploaded by

Santhose
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

Internal Placement Training

Placement Training for Final Years


Programming Questions
# Easy # Medium # Difficult
Day Topic
Questions Questions Questions
Input/ Output Statement
1 25 9 1
and Operators
2 Conditional Statements 15 12 4
3 Looping Statements 15 16 13
4 Arrays 17 10 8
5 Strings 11 11 10

Day 1: Input/Output, Formatting Output and Operators

Level: Easy

1. Display the ASCII value of the input character


Input: 'a'
Expected Output: ASCII value of 'a' is 97

Input: '!'
Expected Output: ASCII value of '!' is 33

2. Get an input of type float with more than 3 decimal points. Display the input value
with 2 decimal points
Input: 123.45678
Expected Output: 123.46

Input: 0.1234567
Expected Output: 0.12
3. Print the floating point input in exponential notation

Input: 123.456
Expected Output: 1.23456e+02

1|Page
Internal Placement Training

Input: 0.000123456
Expected Output: 1.23456e-04

4. Print a number right justified within 8 columns

Input: 123 Expected Output: 123

Input: 987654 Expected Output: 987654

Input: 1.23 Expected Output: 1.23

Input: 0.123456789 Expected Output: 0.123457 (rounded to fit within 8 columns)

Input: 1234567890 Expected Output: 12345678 (trimmed to fit within 8 columns)

5. Write a program to read a floating-point number from the user and print it with
exactly two decimal places.
Input: 3.14159
Expected Output: 3.14

Input: 123.45678
Expected Output: 123.46

Input: 7.5
Expected Output: 7.50
6. Write a program to read an integer from the user and print it right-aligned in a field of
width 10.
Input: 987654321
Expected Output: 987654321

Input: -987
Expected Output: -987
7. Write a program to read a string from the user and print it surrounded by quotation
marks.
Expected Output: "Hello, World!"

2|Page
Internal Placement Training

Input: Programming
Expected Output: "Programming"
8. Write a program to read a date in the format YYYY MM DD from the user and print
it in the format DD/MM/YYYY.
Input: 2024 06 15
Expected Output: 15/06/2024

Input: 1999 12 31
Expected Output: 31/12/1999
9. Write a program to read an integer, a floating-point number, and a string from the
user, then print them in a single line, separated by commas.
Input:
10
3.14
"Hello"
Expected Output: 10, 3.14, Hello

Input:
-5
2.718
"Program"
Expected Output: -5, 2.718, Program
10. Write a program to read a floating-point number representing an amount of money
and print it with a dollar sign and two decimal places.
Input: 123.45
Expected Output: Amount: $123.45

Input: 1000.0
Expected Output: Amount: $1000.00
11. Write a program to read a list of names and ages from the user and print them in two
columns, with the names left-aligned and the ages right-aligned.
Input:
John 25

3|Page
Internal Placement Training

Praveen 30
Kanishk 22
Expected Output:
John 25
Praveen 30
Kanishk 22
12. Write a program to read a floating-point number from the user and print it in a field of
width 10 with 3 decimal places.
Input
123.456
Expected Output
123.456

Input
-987.654321
Expected Output
-987.654

Input
0.123456789

Expected Output
0.123
13. Write a program to read an integer from the user and print it padded with leading
zeros to a total width of 5 digits.
Input
123
Expected Output
00123

Input
9876
Expected Output
09876

4|Page
Internal Placement Training

14. Write a program to read an integer from the user and print it in decimal, hexadecimal,
and octal formats.
Input
123
Expected Output
Decimal: 123
Hexadecimal: 0x7b
Octal: 0o173

Input
255
Expected Output
Decimal: 255
Hexadecimal: 0xff
Octal: 0o377
15. Program to swap two bits.
Input
Enter a byte (0-255): 127
Enter the first bit position (0-7): 0
Enter the second bit position (0-7): 7
Expected Output
Original byte: 127
Byte with swapped bits: 254
16. Program to swap two words/nibbles of a byte.
Input
5
Expected Output
80

Input
0
Expected Output
0

5|Page
Internal Placement Training

Input
255
Expected Output
255
17. Program to swap two numbers without using third variable.
Input
5
10
Expected Output
Before swapping: num1 = 5, num2 = 10
After swapping: num1 = 10, num2 = 5
18. Program to convert temperature from Celsius to Fahrenheit and vice versa.
Input
Celsius: 37
Fahrenheit: 98.6
Expected Output
98.6 Fahrenheit
37.0 Celsius
19. Program to calculate compound interest and simple interest.
Input
Enter principal amount: 1200
Enter interest rate: 2.5
Enter time (in years): 5
Expected Output
Simple Interest: 150.0
Compound Interest: 131.442041
20. Program to calculate the volume of a sphere.
Input
5
Expected Output
523.60

Input
10

6|Page
Internal Placement Training

Expected Output
4188.79
21. Print the perimeter of a rectangle to take its height and width as input.
Input:
Enter the height of the rectangle: 10000
Enter the width of the rectangle: 5000
Expected Output:
The perimeter of the rectangle with height 10000.0 and width 5000.0 is: 30000.0
22. Write a program that reads a forename, surname and year of birth and display the
names and the year one after another sequentially.
Input
Enter forename: Kanishk
Enter surname: Smith
Enter year of birth: 1990

Expected Output
Kanishk Smith 1990
23. Write a program to calculate the sum of three numbers with getting input in one line
separated by a comma.
Input:
10, 20.5, 5
Expected Output:
35.5

Input:
-5, 10, -3
Expected Output:
2.0
24. Program to perform addition, subtraction, multiplication and division of two numbers.
Input
10
5
Expected Output
15.0

7|Page
Internal Placement Training

5.0
50.0
2.0
25. Program to find the third angle of a triangle if two angles are given.
Input
Enter the first angle of the triangle in degrees: 30
Enter the second angle of the triangle in degrees: 60
Expected Output
The third angle of the triangle is: 90.0 degrees

Level: Medium
26. Write a C program to print the following characters in reverse.
Test Characters: 'T‟, 'A', 'P'
Expected Output:
The reverse of TAP is PAT
27. Program to convert specified days into years, weeks and days.
Input
Enter the number of days: 1000
Expected Output
1000 days is equivalent to:
Years: 2
Weeks: 142
Days: 6
28. Program to calculate the distance between the two points
Input
Enter coordinates of first point (x1, y1): 1 2
Enter coordinates of second point (x2, y2): 4 6
Expected Output
Distance between the points (1, 2) and (4, 6) is: 5.00
29. Write a C program to calculate a bike‟s average consumption from the given total
distance (integer value) travelled (in km) and spent fuel (in litters, float number – 2
decimal points).
Input:

8|Page
Internal Placement Training

Enter the total distance traveled (in km): 1000


Enter the fuel spent (in liters): 50.25
Expected Output:
Average consumption of the bike: 19.88 km/liter
30. Program that converts kilometres per hour to miles per hour.
Input:
Enter speed in kilometres per hour: 1500
Expected Output:
Speed in miles per hour: 932.06 mph
31. Write a program that takes hours and minutes as input, and calculates the total number
of minutes.
Input:
30
Expected Output: 180
Input:
10 120
Expected Output: 720

32. Write a program that takes minutes as input, and display the total number of hours and
minutes.
Input
135
Expected Output
Total hours: 2
Remaining minutes: 15
33. Write a C program to read an amount (integer value) and break the amount into the
smallest possible number of bank notes.
Input
Enter an amount: 2563

Expected Output
Amount 2563 can be broken down into:
2 notes of Rs 1000
1 notes of Rs 500

9|Page
Internal Placement Training

0 notes of Rs 100
1 notes of Rs 50
0 notes of Rs 20
1 notes of Rs 10
0 notes of Rs 5
1 notes of Rs 2
1 notes of Rs 1
34. Vohra went to a movie with his friends in a Wave theatre and during break time he
bought pizzas, puffs and cool drinks. Consider the following prices : [CTS]
Rs.100/pizza
Rs.20/puffs
Rs.10/cooldrink
Generate a bill for What Vohra has bought.

Input
Enter the number of pizzas bought: 2
Enter the number of puffs bought: 3
Enter the number of cool drinks bought: 4

Expected Output
Total Bill Amount: Rs. 380

Level: Difficult
35. Given an unsigned integer N. The task is to swap all odd bits with even bits. For
example, if the given number is 23 (00010111), it should be converted to
43(00101011). Here, every even position bit is swapped with an adjacent bit on the
right side(even position bits are highlighted in the binary representation of 23), and
every odd position bit is swapped with an adjacent on the left side
Example:
Input: N = 23
Output: 43

10 | P a g e
Internal Placement Training

Day 2: Decision Making Statements


Level: Easy
1. Write a program to accept two integers and check whether they are equal or not.
Enter first integer: 5
Enter second integer: 5
The two integers 5 and 5 are equal.

Enter first integer: 10


Enter second integer: 15
The two integers 10 and 15 are not equal.
2. Write a program that checks if a given number is positive, negative, or zero.
Enter a number: 10
10 is a positive number.

Enter a number: -5
-5 is a negative number.

Enter a number: 0
The number is zero.
3. Write a program to check whether a given number is even or odd.
Enter an integer: 8
8 is an even number.

Enter an integer: 13
13 is an odd number.
4. Write a program to read the age of a candidate and determine whether he is eligible to
cast his/her own vote.
Enter your age: 21
Congratulations! You are eligible to cast your vote.

Enter your age: 16


Sorry, you are not eligible to cast your vote.
You need to be at least 18 years old to vote.

11 | P a g e
Internal Placement Training

5. Create a program that determines whether a given year is a leap year or not.
Enter a year: 2020
2020 is a leap year.

Enter a year: 2019


2019 is not a leap year.

Enter a year: 1900


1900 is not a leap year.

6. Write a program that takes three numbers as input and finds the largest among them.
Enter three numbers separated by spaces: 10 5 8
The largest number among 10, 5, and 8 is 10.

Enter three numbers separated by spaces: -3 -7 -1


The largest number among -3, -7, and -1 is -1.

7. Write a C program that prints “yes” if the given integer is divisible by 2 or3 and “no”
Enter an integer: 6
Yes

Enter an integer: 9
Yes

Enter an integer: 5
No

8. Write a program to find whether a given number is divisible by both 7and 3.


Enter an integer: 21
21 is divisible by both 7 and 3.

Enter an integer: 14
14 is not divisible by both 7 and 3.

12 | P a g e
Internal Placement Training

Enter an integer: 0
0 is divisible by both 7 and 3.
9. Write a program to accept the height of a person in centimeters and categorize the
person according to their height.
Enter height in centimeters: 140
Person is Short.

Enter height in centimeters: 160


Person is of Average height.

Enter height in centimeters: 175


Person is Tall.

10. Create a program that takes a month number (1-12) as input and displays the number
of days in that month.
Enter month number (1-12): 1
Number of days in month 1 is 31.

Enter month number (1-12): 2


Number of days in month 2 is 28.

Enter month number (1-12): 13


Invalid month number. Please enter a number between 1 and 12.

11. Write a program to calculate profit and loss on a transaction.


Enter the cost price: 100
Enter the selling price: 120
Profit amount: 20.00

Enter the cost price: 150


Enter the selling price: 120
Loss amount: 30.00

Enter the cost price: 100

13 | P a g e
Internal Placement Training

Enter the selling price: 100


No profit, no loss.
12. Write a program to get two numbers from the user and add the last digit of the
numbers.
Enter first number: 123
Enter second number: 456
Sum of last digits 3 and 6 is: 9

Enter first number: 9876


Enter second number: 543
Sum of last digits 6 and 3 is: 9

Enter first number: 100


Enter second number: 20
Sum of last digits 0 and 0 is: 0
13. Write a program using switch case to accept any single digit number and print it in
words.
Enter a single-digit number (0-9): 3
Three

Enter a single-digit number (0-9): 7


Seven

Enter a single-digit number (0-9): 12


Invalid input! Please enter a single-digit number.
14. Write a program to add the 100th place digit of a given two 3 digit numbers.
Enter the first three-digit number: 456
Enter the second three-digit number: 789
Sum of hundreds place digits 4 and 7 is: 11

Enter the first three-digit number: 123


Enter the second three-digit number: 987
Sum of hundreds place digits 1 and 9 is: 10

14 | P a g e
Internal Placement Training

15. Write a program to check if the 10th place digits of the given two 3 digit numbers are
equal.
Enter the first three-digit number: 456
Enter the second three-digit number: 789
Tens place digits 5 and 8 are not equal.

Enter the first three-digit number: 123


Enter the second three-digit number: 987
Tens place digits 2 and 8 are not equal.

Enter the first three-digit number: 345


Enter the second three-digit number: 567
Tens place digits 4 and 5 are equal.

Level: Medium
16. Create a program that checks whether a given character is a vowel or a consonant.
Enter a character: A
A is a vowel.

Enter a character: b
b is a consonant.

Enter a character: 7
Invalid input. Please enter an alphabetic character.

17. Write a program which computes the area of various geometrical shapes using a
menu-driven approach.
Enter your choice (1-4): 1
Enter radius of the circle: 5
Area of the circle = 78.54 square units

Enter your choice (1-4): 2


Enter length and width of the rectangle: 4 6

15 | P a g e
Internal Placement Training

Area of the rectangle = 24.00 square units

Enter your choice (1-4): 3


Enter base and height of the triangle: 7 9
Area of the triangle = 31.50 square units

Enter your choice (1-4): 4


Exiting the program.

18. Write a program that calculates the electricity bill based on the units consumed. The
rate per unit is given as follows:
For the first 50 units: Rs. 3 per unit
For the next 100 units: Rs. 4 per unit
For the remaining units: Rs. 5 per unit

Enter the units consumed: 30


Electricity Bill = Rs. 90.00

Enter the units consumed: 120


Electricity Bill = Rs. 470.00

Enter the units consumed: 200


Electricity Bill = Rs. 820.00
19. Create a program that takes a student's marks in three subjects as input and calculates
the total and average marks. Display the grade according to the following criteria:
Average marks >= 90: Grade A+
Average marks >= 80 and < 90: Grade A
Average marks >= 70 and < 80: Grade B+
Average marks >= 60 and < 70: Grade B
Average marks >= 50 and < 60: Grade C
Average marks < 50: Grade F

Enter marks of three subjects: 95 92 88


Total marks = 275.00

16 | P a g e
Internal Placement Training

Average marks = 91.67


Grade: A+

Enter marks of three subjects: 60 55 58


Total marks = 173.00
Average marks = 57.67
Grade: C

Enter marks of three subjects: 40 45 30


Total marks = 115.00
Average marks = 38.33
Grade: F
20. Write a program that takes a character as input and checks if it is an uppercase letter,
lowercase letter, digit, or special character.
Enter a character: H
H is an uppercase letter.

Enter a character: m
m is a lowercase letter.

Enter a character: 7
7 is a digit.

Enter a character: @
@ is a special character.
21. Create a program that takes the coefficients of a quadratic equation as input and
calculates the roots using the quadratic formula. Display the roots or a message if the
roots are imaginary.
Enter coefficients a, b, and c: 1 2 5
Roots are complex and imaginary:
Root 1 = -1.00 + 2.00i
Root 2 = -1.00 - 2.00i

Enter coefficients a, b, and c: 1 2 1

17 | P a g e
Internal Placement Training

Roots are real and equal:


Root 1 = Root 2 = -1.00
22. Write a program to accept a coordinate point in an XY coordinate system and
determine in which quadrant the coordinate point lies.
Enter the coordinates (x, y): 3.5 4.2
The point (3.50, 4.20) lies in the First quadrant.
Enter the coordinates (x, y): -2.5 4.8
The point (-2.50, 4.80) lies in the Second quadrant.
Enter the coordinates (x, y): -3.9 -2.1
The point (-3.90, -2.10) lies in the Third quadrant.
Enter the coordinates (x, y): 2.6 -5.0
The point (2.60, -5.00) lies in the Fourth quadrant.
23. Write a program to read temperature in centigrade and display a suitable message
according to the temperature state below:
Temp < 0 then Freezing weather
Temp 0-10 then Very Cold weather
Temp 10-20 then Cold weather
Temp 20-30 then Normal in Temp
Temp 30-40 then Its Hot
Temp >=40 then Its Very Hot

Enter the temperature in centigrade: -5


Freezing weather
Enter the temperature in centigrade: 25
Normal in Temp

Enter the temperature in centigrade: 35


Its Hot

24. Write a program to check whether a triangle is Equilateral, Isosceles or Scalene.


Enter the lengths of the three sides of the triangle:
Side 1: 5
Side 2: 5
Side 3: 5

18 | P a g e
Internal Placement Training

It is an Equilateral triangle.

Enter the lengths of the three sides of the triangle:


Side 1: 4
Side 2: 4
Side 3: 6

It is an Isosceles triangle.

Enter the lengths of the three sides of the triangle:


Side 1: 3
Side 2: 4
Side 3: 5

It is a Scalene triangle.
25. Write a program to check whether a triangle can be formed with the given values for
the angles.
Input:
Enter the three angles of the triangle:
Angle 1: 60
Angle 2: 60
Angle 3: 60
Output: The angles 60, 60, and 60 can form a triangle.

Input:
Enter the three angles of the triangle:
Angle 1: 45
Angle 2: 60
Angle 3: 80
Output: The angles 45, 60, and 80 cannot form a triangle.
26. Write a program to check whether a character is an alphabet, digit or special
character.
Input: A

19 | P a g e
Internal Placement Training

Output: Alphabet
Input: 5
Output: Digit
Input: $
Output: Special character

27. A teacher tries to relate between theAngles inscribed in a circle and the direction.
Initially she wants to teach them the directions related with theangle‟s 0,90,180,270
indicating East, North, West, South respectively. Write a C program using selection
statement to denote the direction graphically corresponding to theangle entered.
Input Format:
Input consists of a single integer corresponding to the angle entered by the student
Output Format:
Output consists of the strings “North”,“South”, “East”, “West” and “Invalid”.
Sample input and output:
Enter the angle:
270
270 corresponds to South
Sample input and output:
Enter the angle:
375
Invalid

Level: Difficult
28. Implement a simple Rock, Paper, Scissors game. Take user input for their choice and
randomly generate the computer's choice. Use if-else statements to determine the
winner based on the rules of the game.
Welcome to Rock, Paper, Scissors!
Enter your choice:
0 - Rock
1 - Paper
2 - Scissors
Your choice: 1

20 | P a g e
Internal Placement Training

Your choice: Paper


Computer's choice: Rock

You win!
29. Think of a number between 1 and 100. Let the user guess the number. Use a loop with
if statements to check if the guess is correct, higher, or lower, and provide hints to the
user.
Welcome to the Guess the Number game!
I have picked a number between 1 and 100. Try to guess it!
Enter your guess: 50
Too low. Try again.
Enter your guess: 75
Too high. Try again.
Enter your guess: 63
Too high. Try again.
Enter your guess: 56
Too low. Try again.
Enter your guess: 59
Congratulations! You guessed the number 59 correctly in 5 attempts.
30. Simulate a simple vending machine. Define prices for different items. Ask the user for
their choice and the amount inserted. Use nested if statements to check for sufficient
funds, dispense the item, and provide change if necessary.
Welcome to the Vending Machine!
1. Coke - $1.50
2. Snickers - $1.20
3. Chips - $1.00
4. Water - $0.80
5. Exit
Enter your choice (1-5): 2
Please insert amount ($1.20): 1.50
Thank you for your purchase! Item dispensed.
Your change: $0.30

21 | P a g e
Internal Placement Training

31. Sujith is going to Goa this week end. As the train tickets are unavailable, he decides to
go by bus. He books his tickets through a website. Write a C program to find whether
he booked a window seat or not. Assume that there are maximum 11 rows in a bus.
Input and Output Format:
Input consists of two integers. The first integer corresponds to the number of seats per
row in the bus. The second integer corresponds to the seat number.
Sample Input and Output 1:
Enter number of seats per row
4
Enter the seat number
36
Window Seat
Sample Input and Output 2:
Enter number of seats per row
3
Enter the seat number
34
Invalid Seat Number
Sample Input and Output 3:
Enter number of seats per row
3
Enter the seat number
20
Aisle Seat

22 | P a g e
Internal Placement Training

Day 3: Looping
Level: Easy
1. Write a program to print numbers from 0 to 10 and 10 to 0

Output:
Numbers from 0 to 10:
0 1 2 3 4 5 6 7 8 9 10
Numbers from 10 to 0:
10 9 8 7 6 5 4 3 2 1 0

2. Write a program that prompts the user to input a series of integers until the user stops
entering 0 using a while loop. Calculate and print the sum of all the positive integers
entered.

Input:
Enter the values (enter 0 to stop):
3
5
-7
8
1
-4
5
0
Output:
Sum of positive integers: 22

3. Write a program that calculates the product of numbers from 1 to 5

Output:
The product of numbers from 1 to 5 = 120

23 | P a g e
Internal Placement Training

4. Write a program that prompts the user to input a series of numbers until they input
number match with the previous number.

Input:
Enter the numbers:
4
1
3
8
2
2
Output:
Number matched with the previous number

5. Write a program that prompts the user to input a username. Use a while loop to keep
asking for a username until a valid one is entered (e.g., at least 8 characters long).

Input and Output:


Note: Username should have at least 8 characters.
Enter the Username: alice
Wrong Input: Username should have at least 8 characters.
Enter the Username: alice12
Wrong Input: Username should have at least 8 characters.
Enter the Username: alice123
Hey!!! Warm Welcome to You :)

6. Write a program that calculates and prints the sum of cubes of even numbers up to a
specified limit.

Input:
Enter the limit: 20
Output:
The sum of cubes of even numbers from 1 to 20 is 24200

24 | P a g e
Internal Placement Training

7. Write a program that prompts the user to enter a positive integer. Use a while loop to
print the multiplication table for that number up to 10.

Input:
Enter the number: 2
Output:
Multiplication Table for 2
1x2=2
2x2=4
3x2=6
4x2=8
5 x 2 = 10
6 x 2 = 12
7 x 2 = 14
8 x 2 = 16
9 x 2 = 18
10 x 2 = 20

8. Write a program that calculates the sum of even and odd numbers from 1 to 50 using
do...while loop.

Output:
The sum of even numbers from 1 to 5 is 650
The sum of odd numbers from 1 to 5 is 625

9. Write a program that prompts the user to enter a series of numbers until they input a
negative number using do…while.

Input:
Enter the numbers:
3
7
1
98

25 | P a g e
Internal Placement Training

45
-3
Output:
Thank you for your input.

10. Write a program to compute the sum and average of the first 10 natural numbers.

Output:
The sum of first 10 natural numbers is 55
The average of first 10 natural numbers is 5.5

11. Write a program that displays the n terms of square natural numbers and their sum.

Input:
Enter the terms: 5
Output:
The square natural upto 5 terms are: 1 4 9 16 25
The Sum of Square Natural Number upto 5 terms is 55

12. Print all ASCII character with their values.

Output:
Uppercase Letters
----------------------
Character Value
A 65
B 66
.
.
.
Z 90
Lowercase Letters
----------------------
Character Value

26 | P a g e
Internal Placement Training

a 97
b 98
.
.
.
z 122

13. Find power of a number using for loop.

Input:
Enter the base value: 2
Enter the power value: 5
Output:
2 power 5 is 32

14. Write a program to add all the numbers that are divisible by 3 and 5 from 1 to 25.

Output:
The sum of numbers that are divisible by 3 and 5 in the range of 1 to 25 is 15

15. Write a program to simulate “Fizz Buzz” game. Display “Fizz”, if a number is
divisible by 3. Display “Buzz”, if a number is divisible by 5. Display “Fizz Buzz”, if a
number is divisible by both 3 and 5.

Input:
Enter the terms: 15
Output:
Let us start the game
1
2
Fizz
4
Buzz
Fizz

27 | P a g e
Internal Placement Training

7
8
Fizz
Buzz
11
Fizz
13
14
Fizz Buzz

Level: Medium
16. Program to find factorial of a number.

Input:
Enter the number: 5
Output:
5! is 120

17. Write a program to display the number in reverse order.

Input:
Enter the number: 2326
Output:
Reverse of 2326 is 6232

18. Program to check whether number is Palindrome or not

Input:
Enter the number: 3473
Output:
3473 is not a Palindrome

Input:

28 | P a g e
Internal Placement Training

Enter the number: 3443


Output:
3443 is a Palindrome number

19. Program to check whether number is Perfect square or not

Input:
Enter the number: 16
Output:
16 is a perfect square

Input:
Enter the number: 33
Output:
33 is not a perfect square

20. Program to check whether number is Prime or not.

Input:
Enter the number: 17
Output:
17 is a prime number

Input:
Enter the number: 16
Output:
16 is not a prime number

21. Program to check whether a number if Armstrong or not.

Input:
Enter the number: 153
Output:
153 is an Armstrong number

29 | P a g e
Internal Placement Training

Input:
Enter the number: 123
Output:
123 is not an Armstrong number

22. Program to print all leap years from 1 to N.

Input:
Enter the starting year:
Enter the ending year:
Output:
The leap years are 2000, 2004, 2008, 2012, 2016, 2020, 2024, 2028, 2032, 2036,
2040, 2044, and 2048.

23. Program to convert number from Decimal to Binary.

Input:
Enter the decimal value: 12
Output:
Binary value – 1100

24. Program to convert number from Binary to Decimal.

Input:
Enter the binary value: 110
Output:
Decimal value – 12

25. Write a program to find HCF (GCD) of two numbers.

Input:
Enter the first number: 1095
Enter the second number: 1168
Output:

30 | P a g e
Internal Placement Training

The HCF of 1095 and 1168 is 73

26. Program to find LCM of two numbers.

Input:
Enter the first number: 1095
Enter the second number: 1168
Output:
The LCM of 1095 and 1168 is 17520

27. Program to print first N perfect square numbers.

Input:
Enter the limit: 10
Output:
The first 10 perfect square numbers are 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.

28. Program to check whether a number is Strong number or not.

Input:
Enter the number: 145
Output:
145 is a strong number

Input:
Enter the number: 15
Output:
15 is not a strong number

29. Program to print all Strong numbers between 1 to n.

Input:
Enter the limit: 1000
Output:

31 | P a g e
Internal Placement Training

The strong numbers are 1, 2, 145

30. Program to print Fibonacci series up to n terms.

Input:
Enter the limit: 10
Output:
The Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34

Level: Difficult

31. Write a program in C to display the n terms of a harmonic series and their sum.
1 + 1/2 + 1/3 + 1/4 + 1/5 ... 1/n terms

Input:
Enter the terms: 5
Output:
1/1 + 1/2 + 1/3 + 1/4 + 1/5 +
The sum of the series upto 5 terms is 2.283334

32. Write a program in C to display the sum of the series [ 9 + 99 + 999 + 9999 ...].

Input:
Enter the terms: 5
Output:
9 + 99 + 999 + 9999 + 99999 +
The sum of the series is 111105

33. Write a program in C to find the sum of the series [x - x^3 + x^5 + ......].

Input:
Enter the value of x: 3
Enter the number of terms: 5
Output:

32 | P a g e
Internal Placement Training

The sum is 16.375000

34. Count all the unique digits in a given number.

Input:
Enter the number: 27745
Output:
There are 3 unique numbers in the given number 2745

35. Given a positive integer n, find the smallest integer which has exactly the same digits
existing in the integer n and is greater in value than n. If no such positive integer,
display the appropriate message.

Input:
Enter the number: 21
Output:
The smallest number in 21 is 12

Input:
Enter the number: 13
Output:
Sorry!!! There are no Numbers

36. Write an algorithm to determine if a number is "happy". A happy number is a


number defined by the following process: Starting with any positive integer, replace
the number by the sum of the squares of its digits, and repeat the process until the
number equals 1 (where it will stay), or it loops endlessly in a cycle which does not
include 1. Those numbers for which this process ends in 1 are happy numbers.

Input:
Enter the number: 13
Output:
13 is a happy number :)

33 | P a g e
Internal Placement Training

Input:
Enter the number: 11
Output:
11 is not a happy number :(

37. Write a program to check whether a given number is an ugly number. Ugly numbers
are positive numbers whose prime factors only include 2, 3, and/or 5.

Input:
Enter the number: 27
Output:
27 is not an ugly number :)

Input:
Enter the number: 12
Output:
12 is an ugly number :)

38. Write a program to check whether a given number is a Disarium number. A number
is called Disarium if the sum of its digits powered with their respective positions is
equal to the number itself.

Input:
Enter the number: 135
Output:
135 is a Disarium number

39. Write a program to check whether a given number is a Kaprekar number. A


Kaprekar number for a given base is a non-negative integer, the representation of
whose square can be split into two parts that add up to the original number.

Input:
Enter the number: 45
Output:

34 | P a g e
Internal Placement Training

45 is Kaprekar number

40. Write a program to check whether a given number is a self-dividing number. A self-
dividing number is a number that is divisible by every digit it contains.

Input:
Enter the number: 128
Output:
128 is a self-dividing number

41. Write a program to check whether a given number is a narcissistic number. A


narcissistic number is a number that is the sum of its own digits each raised to the
power of the number of digits.

Input:
Enter the number: 153
Output:
153 is a narcissistic number

Input:
Enter the number: 9474
Output:
9474 is a narcissistic number

42. Implement the following Function [Accenture]


void differenceofSum(n. m)
The function accepts two integers n, m as arguments Find the sum of all numbers in
range from 1 to m(both inclusive) that are not divisible by n. Return difference
between sum of integers not divisible by n with sum of numbers divisible by n.
Assumption:
n>0 and m>0
Sum lies between integral range

Example

35 | P a g e
Internal Placement Training

Input
n:4
m:20
Output
90
Explanation
Sum of numbers divisible by 4 are 4 + 8 + 12 + 16 + 20 = 60
Sum of numbers not divisible by 4 are 1 +2 + 3 + 5 + 6 + 7 + 9 + 10 + 11 + 13 + 14 +
15 + 17 + 18 + 19 = 150
Difference 150 – 60 = 90
Sample Input
n:3
m:10
Sample Output
19

43. Problem Statement [Capgemini]


A carry is a digit that is transferred to left if sum of digits exceeds 9 while adding two
numbers from right-to-left one digit at a time
You are required to implement the following function.
Int NumberOfCarries(int num1 , int num2);
The functions accepts two numbers „num1‟ and „num2‟ as its arguments. You are
required to calculate and return the total number of carries generated while adding
digits of two numbers „num1‟ and „ num2‟.
Assumption: num1, num2>=0

Example:

 Input
o Num 1: 451
o Num 2: 349
 Output
o 2
Explanation:
Adding „num 1‟ and „num 2‟ right-to-left results in 2 carries since ( 1+9) is 10. 1 is
carried and (5+4=1) is 10, again 1 is carried. Hence 2 is returned.
Sample Input
Num 1: 23

36 | P a g e
Internal Placement Training

Num 2: 563
Sample Output
0

Pattern
44. Write a C program to display a pattern like a right angle triangle with a number.

45. Write a program in C to make such a pattern like a right angle triangle with a number
which will repeat a number in a row.

46. Write a program in C to make such a pattern like a right angle triangle with the
number increased by 1.

47. Write a program in C to make a pyramid pattern with numbers increased by 1.

48. Write a program in C to make a pyramid pattern.

49. Write a program in C to print Floyd's Triangle.

37 | P a g e
Internal Placement Training

50. Write a program in C to display a pattern like a diamond.

51. Write a C program to display Pascal's triangle.

52. Write a C program to display the pyramid pattern using the alphabet.

53. Hollow pattern

54. Inverted star pattern

55. Inverted Hollow pattern

38 | P a g e
Internal Placement Training

56. Pyramid

1
1 3 1
1 3 5 3 1
1 3 5 7 5 3 1
1 3 5 7 9 7 5 3 1

57. Pyramid

3
4 5 4
5 6 7 6 5
6 7 8 9 8 7 6

58. Right Angled triangle


1
2 * 2
3 * 3 * 3
4 * 4 * 4 * 4

39 | P a g e
Internal Placement Training

Day 4: Arrays
Level: Easy
1. Write a program to store elements in an array and print them.

Input:
Enter the limit: 5
Enter the numbers:
34
65
234
89
456
Output:
The elements in the array are
34
65
234
89
456

2. Write a program to read n number of values in an array and display them in reverse
order.

Input:
Enter the limit: 5
Enter the numbers:
5
4
3
2
1
Output:
The elements in the array are

40 | P a g e
Internal Placement Training

5
4
3
2
1
The reversed order of elements in the array,
1
2
3
4
5

3. Read two arrays and count the number of element that equal in both arrays with
respect to the index.

Input:
Enter the limit: 5
Enter the elements for the first array: 23 45 546 867 124
Enter the elements for the second array: 456 45 434 867 124
Output:
The elements in first array – 23 45 546 867 124
The elements in second array – 456 45 434 867 124
Common elements – 45 867 124
Number of common elements are 3

4. Read two equally sized array and Divide the first array element by second array
element.

Input:
Enter the limit: 5
Enter the elements for the first array: 10 20 30 40 50
Enter the elements for the second array: 1 2 3 4 5
Output:
First array: 10 20 30 40 50

41 | P a g e
Internal Placement Training

Second array: 1 2 3 4 5
Resultant array: 10 10 10 10 10

5. Write a program to find the sum of all elements of the array.

Input:
Enter the limit: 5
Enter the elements: 3 6 1 7 9
Output:
The sum of all elements of the array is 26

6. Write a program to sum all the even indexed elements of the array.

Input:
Enter the limit: 5
Enter the elements: 13 26 31 47 59
Output:
The sum of all elements of the array is 103

7. Write a program to copy the elements of one array into another array.

Input:
Enter the limit: 5
Enter the elements: 23 456 567 23 576
Output:
The copied array - 23 456 567 23 576

8. Write a program to count the total number of duplicate elements in an array.

Input:
Enter the limit: 5
Enter the elements: 9 5 3 3 5
Output:
The elements in the array are 9 5 3 3 5

42 | P a g e
Internal Placement Training

The duplicate elements in the array are 3 5


The total duplicate elements are 2

9. Write a program to print all unique elements in an array.

Input:
Enter the limit: 6
Enter the elements: 9 5 3 3 5 6
Output:
The elements in the array are 9 5 3 3 5 6
The unique elements in the array are 9 6

10. Write a program to separate odd and even integers into separate arrays.

Input:
Enter the limit: 6
Enter the elements: 234 657 124 75 12 64
Output:
The elements in the array are 234 657 124 75 12 64
Odd elements - 657 75
Even elements - 234 124 12 64

11. Write a program to sort elements of an array in ascending order.

Input:
Enter the limit: 5
Enter the elements: 293 938 23 4 376
Output:
Before Sorting - 293 938 23 4 376
After Sorting – 4 23 293 376 938

12. Write a program for a 2D array of size 3x3 and print the matrix.

Input:

43 | P a g e
Internal Placement Training

Enter the elements: 1 2 3 4 5 6 7 8 9


Output:
3 x 3 matrix
1 2 3
4 5 6
7 8 9

13. Write a program for adding two matrices of the same size.

Input:
Enter the row size: 3
Enter the column size: 3
Enter the elements for the first matrix: 1 2 3 4 5 6 7 8 9
Enter the elements for the second matrix: 1 2 3 4 5 6 7 8 9
Output:
First 3 x 3 matrix
1 2 3
4 5 6
7 8 9
Second 3 x 3 matrix
1 2 3
4 5 6
7 8 9
Resultant 3 x 3 matrix
2 4 6
8 10 12
14 16 18

14. Write a program C for the subtraction of two matrices.

Input:
Enter the row size: 3
Enter the column size: 3
Enter the elements for the first matrix: 1 2 3 4 5 6 7 8 9

44 | P a g e
Internal Placement Training

Enter the elements for the second matrix: 1 2 3 4 5 6 7 8 9


Output:
First 3 x 3 matrix
1 2 3
4 5 6
7 8 9
Second 3 x 3 matrix
1 2 3
4 5 6
7 8 9
Resultant 3 x 3 matrix
0 0 0
0 0 0
0 0 0

15. Write a program to find the transpose of a given matrix.

Input:
Enter the row size: 3
Enter the column size: 3
Enter the elements: 1 2 3 4 5 6 7 8 9
Output:
3 x 3 matrix
1 2 3
4 5 6
7 8 9
Transposed 3 x 3 matrix
1 4 7
2 5 8
3 6 9

16. Write a program to find the sum of rows and columns of a matrix.

45 | P a g e
Internal Placement Training

Input:
Enter the row size: 3
Enter the column size: 3
Enter the elements: 1 2 3 4 5 6 7 8 9
Output:
3 x 3 matrix
1 2 3
4 5 6
7 8 9
Row Sum = [6 15 24]
Column Sum = [12 15 18]

17. Write a program to accept a matrix and determine whether it is a sparse matrix.

Input:
Enter the row size: 3
Enter the column size: 3
Enter the elements for the first matrix: 1 2 3 0 5 0 7 0 9
Output:
3 x 3 matrix
1 2 3
0 5 0
7 0 9
The given matrix is not a sparse matrix

Level: Medium
18. Write a program to merge two arrays of the same size sorted in descending order.

Input:
Enter the limit of the first array: 3

46 | P a g e
Internal Placement Training

Enter the elements for the first array:


23 90 12
Enter the limit of the second array: 3
Enter the elements for the second array:
45 86 99
Output:
First array – [23, 90, 12]
Second array – [45, 89, 99]
Merged array in descending order – [99, 90, 89, 45, 23, 12]

19. Write a program to count the frequency of each element of an array.

Input:
Enter the limit: 5
Enter the elements: 8 9 6 8 6
Output:
Input values – [8, 9, 6, 8, 6]
Frequency Table
82
91
62

20. Write a program to find the maximum and minimum elements in an array.

Input:
Enter the limit: 5
Enter the elements: 23 34 5 123 43
Output:
Input values – [23, 34, 5, 123, 43]
Maximum Number is 123
Minimum Number is 5

21. Write a program to insert values in the array (unsorted list).

47 | P a g e
Internal Placement Training

Input:
Enter the limit: 5
Enter the elements: 9 5 8 0 4
Enter the number to be inserted: 1
Output:
Input values – [9, 5, 8, 0, 4]
Values after insertion – [9, 5, 8, 0, 4, 1]

22. Write a program to insert the values in the array (sorted list).

Input:
Enter the limit: 5
Enter the elements: 9 5 8 0 4
Enter the number to be inserted: 1
Output:
Input values – [9, 5, 8, 0, 4]
Sorted array – [0, 4, 5, 8, 9]
Values after insertion – [0, 1, 4, 5, 8, 9]

23. Write a program to delete an element at a desired position from an array.

Input:
Enter the limit: 5
Enter the elements: 4 8 3 9 1
Enter the position for deletion: 3
Output:
Input values – [4, 8, 3, 9, 1]
Values after insertion – [4, 8, 9, 1]

24. Write a program to find the second largest element in an array.

Input:
Enter the limit: 5
Enter the elements: 264 789 234 435 457

48 | P a g e
Internal Placement Training

Output:
457 is the second largest element in the given array

25. Write a program to find the largest sum of contiguous subarrays in an array.

Input:
Enter the limit: 9
Enter the elements: 8 3 8 -5 4 3 -4 3 5
Output:
The largest sum of contiguous subarray is: 21

26. Write a program to find the missing number in a given array. There are no duplicates
in the list.

Input:
Enter the limit: 8
Enter the elements: 1 3 4 2 5 6 9 8
Output:
7 is missing in [1, 3, 4, 2, 5, 6, 9, 8]

27. Write a program to rotate an array by N positions.

Input:
Enter the limit: 8
Enter the elements: 1 3 4 2 5 6 9 8
Enter the position: 4
Output:
The given array is: 1 3 4 2 5 6 9 8
From 4th position the values of the array are: 5 6 9 8
Before 4th position the values of the array are : 1 3 4 2
After rotating from 4th position the array is:
56981342

49 | P a g e
Internal Placement Training

Level: Difficult
28. Get n numbers and create the second array that has the first digit of all the numbers in
even position and last digit of all the elements in odd position.

Input:
[23, 45, 12, 567, 989, 34]
Output:
[3, 4, 2, 5, 9, 3]

29. Given an array nums of n integers where n > 1, return an array output such that
output[i] is equal to the product of all the elements of nums except nums[i]. [TCS]

Input: [1,2,3,4]
Output: [24,12,8,6]

30. Find the contiguous subarray within an array nums (containing at least one number)
which has the largest sum and return its sum. [TCS, CTS]

Input: [-2,1,-3,4,-1,2,1,-5,4]
Output: 6

31. Given N leaves numbered from 1 to N . A caterpillar at leaf 1, jumps from leaf to leaf
in multiples of Aj (Aj, 2Aj, 3Aj). j is specific to the caterpillar. Whenever a caterpillar
reaches a leaf, it eats it a little bit.. You have to find out how many leaves, from 1 to
N, are left uneaten after all K caterpillars have reached the end. Each caterpillar has
its own jump factor denoted by Aj, and each caterpillar starts at leaf number 1.
[Infosys]

Input:
N=10 K=3
arr[] = {2, 3, 5}
Output: 2

50 | P a g e
Internal Placement Training

Explanation: The leaves eaten by the first caterpillar are (2, 4, 6, 8, 10). The leaves
eaten by the second caterpilllar are (3, 6, 9). The leaves eaten by the third caterpilllar
are (5, 10). Ultimately, the uneaten leaves are 1, 7 and their number is 2.

32. Given arrival and departure times of all trains that reach a railway station. Find the
minimum number of platforms required for the railway station so that no train is kept
waiting. Consider that all the trains arrive on the same day and leave on the same day.
Arrival and departure time can never be the same for a train but we can have arrival
time of one train equal to departure time of the other. At any given instance of time,
same platform can not be used for both departure of a train and arrival of another
train. In such cases, we need different platforms. [Infosys]

Input: n = 6
arr[] = {0900, 0940, 0950, 1100, 1500, 1800}
dep[] = {0910, 1200, 1120, 1130, 1900, 2000}
Output: 3

33. Problem Description :[Accenture]


The function accepts two positive integers „r‟ and „unit‟ and a positive integer array
„arr‟ of size „n‟ as its argument „r‟ represents the number of rats present in an area,
„unit‟ is the amount of food each rat consumes and each ith element of array „arr‟
represents the amount of food present in „i+1‟ house number, where 0 <= i
Note:
Return -1 if the array is null
Return 0 if the total amount of food from all houses is not sufficient for all the rats.
Computed values lie within the integer range.

Input:
r: 7
unit: 2
n: 8
arr: 2 8 3 5 7 4 1 2
Output:
4

51 | P a g e
Internal Placement Training

Explanation:
Total amount of food required for all rats = r * unit
= 7 * 2 = 14.
The amount of food in 1st houses = 2+8+3+5 = 18. Since, amount of food in 1st 4
houses is sufficient for all the rats. Thus, output is 4.

34. Write a program that takes an integer M and M integer array elements as input. The
program needs to find the minimum difference between two elements in the integer
array. The program then needs to print all those pairs of elements that have the
minimum difference. If more than one pair has the minimum difference, then the
program should print the output in the ascending order, if an element exists in two or
more pairs, then it should be printed two times or more. [Zoho]

Input: 4
55 44 33 22
Output: 22 33 33 44 44 55
Explanation: The minimum difference between two elements is 11. Hence the pairs
are printed in the ascending order. Here 33 and 44 appear in two different pairs; hence
both are printed twice.

Input: 5
1 99 22 44 1001
Output: 1 22

35. Given an array as input, The condition is if the number is repeated you must add
thenumber and put the next index value to 0. If the number is 0 print it at the last.
[Zoho]

Eg: arr[] = { 0, 2, 2, 2, 0, 6, 6, 0, 8}
Output: 4 2 12 8 0 0 0 0 0

52 | P a g e
Internal Placement Training

Day 5: Strings
Level: Easy
1. Write a program to input a string and print it.

Input:
Enter the string: Welcome to Internal Programming Training
Output:
The string entered is “Welcome to Internal Programming Training”

2. Write a program to find the length of a string using library functions.

Input:
Enter the string: Placement
Output:
The word “Placement” has 9 characters.

3. Write a program to separate individual characters from a string.

Input:
Enter the string: Training
Output:
The characters in the given string are: T, r, a, i, n, i, n, g

4. Write a program to copy one string to another string.

Input:
Enter the string: company
Output:
Original String – company
Copied string – company

5. Write a program to count the total number of vowels or consonants in a string.

Input:

53 | P a g e
Internal Placement Training

Enter the string: Placement


Output:
There are 3 vowels and 6 consonants in the string “Placement”.

6. Write a program to find the maximum number of occurring characters in a string.

Input:
Enter the string: malayalam
Output:
„a‟ is the character the occurs more number of times in the given string “malayalam”.

7. Write a program to print individual characters of a string in reverse order.

Input:
Enter the string: Placement
Output:
Original string – Placement
Reversed string – tnemecalP

8. Write a program to count the total number of words in a string.

Input:
Enter the string: Internal programming training for final years
Output:
Number of words - 6

9. Write a program to compare two strings using string library functions.

Input:
Enter the first string: Placement
Enter the second string: Placed
Output:
Both strings are not equal

54 | P a g e
Internal Placement Training

10. Write a program to read a sentence and replace lowercase characters with uppercase
and vice versa.

Input:
Enter the string: Placement Training
Output:
Original string – Placement Training
Toggled string – pLACEMENT tRAINING

11. Check if the given string is palindrome.

Input:
Enter the string: rotator
Output:
rotator is a palindrome

Level: Medium
12. Write a program in C to find the length of a string without using library functions.

Input:
Enter the string: Placement
Output:
The word “Placement” has 9 characters.

13. Write a C program to sort a string array in ascending order.

Input:
Enter the limit: 3
Enter the string:
python
c
java
Output:

55 | P a g e
Internal Placement Training

Before Sorting – [python, c, java]


After Sorting – [c, java, python]

14. Write a program in C to extract a substring from a given string.

Input:
Enter the string: This is five days placement training
Enter the position to start extraction: 8
Enter the length of the substring: 4
Output:
The extracted substring is “five”

15. Write a C program to check whether a substring is present in a string.

Input:
Enter the string: training
Enter the substring: rain
Output:
“rain” is present in “training”

Input:
Enter the string: Residential Placement Training
Enter the substring: Placement
Output:
“Placement” is present in “Residential Placement Training”

16. Write a program in C to count the total number of alphabets, digits and special
characters in a string.

Input:
Enter the string: alice123wonder#land24
Output:
Number of alphabets – 14
Number of digits – 5

56 | P a g e
Internal Placement Training

Number of special characters – 1

17. Write a program in C to compare two strings without using string library functions.

Input:
Enter the first string: Placement
Enter the second string: Placed
Output:
Both strings are not equal

18. Write a program in C to find the number of times a given word 'the' appears in the
given string.

Input:
Enter the string: This is the sample test case for the given program
Output:
Number of times „the‟ appears - 2

19. Write a program in C to find the largest and smallest words in a string.

Input:
Enter the string: Nokia launches a new mobile
Output:
Largest word – launches
Smallest word - a

20. Write a program in C to replace the spaces in a string with a specific character.

Input:
Enter the string: I enjoy watching comedy movies
Enter the special character to be replaced: @
Output:
Original string - I enjoy watching comedy movies
Altered string – I@enjoy@watching@comedy@movies

57 | P a g e
Internal Placement Training

21. Write a C program to count each character in a given string.

Input:
Enter the string: have a cup of tea
Output:
Frequency table
h 1
a 3
v 1
e 2
c 1
u 1
p 1
o 1
f 1
t 1

22. Remove the vowels from the given input string.

Input:
Enter the string: placement
Output:
Original string: placement
Altered string: plcmnt

Level: Hard
23. Get two string array such that one contains the names with initial and another array
contains the family names. Match and Replace the initial with the family name such
that family name appears at the end. (Assume that the initials are unique).

For example,
Input:

58 | P a g e
Internal Placement Training

[R.Smith, H.Mathew, L.George, W.Davis]


[Lewis, White, Hughes, Robert]
Output:
[Smith Robert, Mathew Hughes, George Lewis, Davis White]

24. Given a non-palindrome string check whether it can be converted to a palindrome


string.

For example,
Input:
Java
Output:
No, it is not possible :(
Input:
off
Output:
Yes, it is possible :)

25. Given a string containing numbers and other characters, find the sum of all the
numbers in the string.

Example 1:
Input: "abc12def34"
Output: 46
Example 2:
Input: "1a2b3c"
Output: 6

26. Problem Description : [Accenture]


The Binary number system only uses two digits, 0 and 1 and number system can be
called binary string. You are required to implement the following function:
int OperationsBinaryString(char* str);
The function accepts a string str as its argument. The string str consists of binary
digits eparated with an alphabet as follows:

59 | P a g e
Internal Placement Training

– A denotes AND operation


– B denotes OR operation
– C denotes XOR Operation
You are required to calculate the result of the string str, scanning the string to right
taking one opearation at a time, and return the same.
Note:
No order of priorities of operations is required
Length of str is odd
If str is NULL or None (in case of Python), return -1

Input:
str: 1C0C1C1A0B1
Output:
1
Explanation:
The alphabets in str when expanded becomes “1 XOR 0 XOR 1 XOR 1 AND 0 OR
1”, result of the expression becomes 1, hence 1 is returned.
Sample Input:
0C1A1B1C1C1B0A0
Output:
0

27. Consider a string, S, that is a series of characters, each followed by its frequency as an
integer. The string is not compressed correctly, so there may be multiple occurrences
of the same character. A properly compressed string will consist of one instance of
each character in alphabetical order followed by the total count of that character
within the string. [IBM]
28. Write a program that will take one string as input. The program will then remove
vowels a, e, i, o, and u (in lower or upper case ) from the string. If there are two or
more vowels that occur together then the program shall ignore all of those vowels.
[Zoho]

Example 1
Input: Cat

60 | P a g e
Internal Placement Training

Output: Ct
Example 2
Input: Compuuter
Output: Cmpuutr

29. Write a program that will take a string as input. The program will then determine
whether each left parenthesis „(‟ has a matching right parenthesis „)‟ and also all the
„)‟ has a consecutive „(„. If so, the program will print 0 else the program will print 1.
[Zoho]

Example 1
Input: HELLO AND (WELCOME (TO THE) TCEA (CONTEST)TODAY)IS
(SATURDAY())
Output: 0
Example 2
Input: (9*(7-2)*(1*5)
Output: 0

30. Write a program that receives a word A and some texts as input. You need to output
the texts (without modifying them) in the ascending order of the number of
occurrences of the word A in the texts. The input is as follows: an integer M(between
1 and 100, inclusive), followed by the word A in the next line, and some text in each
of the M next lines. [Capgemini]
Note: The texts and the word A contain only lowercase Latin letters (a,b,c…,z) and
blank spaces (“ ”). The maximum size of the texts and the word A is 100 Characters.
Every text has a different number of occurrences of the word A.
Note 2:you must print one text per line without modifying the texts.

Example 1
Input: 2
Java
I hate java
Python is a good programming language
Output: Python is a good programming language

61 | P a g e
Internal Placement Training

I hate java
Example 2
Input: 3
python
I like to code in python
python is named after a show name monty python and not after the snake
python
I think python is good i think python is important than php
Output: i like to code in python
i think python is good i think python is important than php
python is named after a show name monty python and not after the snake
python

31. A furnishing company is manufacturing a new collection of curtains. The curtains are
of two colors aqua(a) and black (b). The curtains color is represented as a string(str)
consisting of a‟s and b‟s of length N. Then, they are packed (substring) into L number
of curtains in each box. The box with the maximum number of „aqua‟ (a) color
curtains is labeled. The task here is to find the number of „aqua‟ color curtains in the
labeled box. [TCS]
Note :
If „L‟ is not a multiple of N, the remaining number of curtains should be considered as
a substring too. In simple words, after dividing the curtains in sets of „L‟, any curtains
left will be another set(refer example 1)

Example 1:
Input :
bbbaaababa -> Value of str

3 -> Value of L
Output:
3 -> Maximum number of a‟s
Explanation:
From the input given above.
Dividing the string into sets of 3 characters each

62 | P a g e
Internal Placement Training

Set 1: {b,b,b}
Set 2: {a,a,a}
Set 3: {b,a,b}
Set 4: {a} -> leftover characters also as taken as another set
Among all the sets, Set 2 has more number of a‟s. The number of a‟s in set 2 is 3.
Hence, the output is 3.
Example 2:
Input :
abbbaabbb -> Value of str
5 -> Value of L
Output:
2 -> Maximum number of a‟s
Explanation:
From the input given above,
Dividing the string into sets of 5 characters each.
Set 1: {a,b,b,b,b}
Set 2: {a,a,b,b,b}
Among both the sets, set 2 has more number of a‟s. The number of a‟s in set 2 is 2.
Hence, the output is 2.
Constraints:
1<=L<=10
1<=N<=50
The input format for testing
The candidate has to write the code to accept two inputs separated by a new line.
First input- Accept string that contains character a and b only
Second input- Accept value for N(Positive integer number)
The output format for testing
The output should be a positive integer number of print the message(if any) given in
the problem statement.(Check the output in Example 1, Example 2).

63 | P a g e

You might also like