Internal Programming Training Questions
Internal Programming Training Questions
Level: Easy
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
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
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
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.
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.
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.
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
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.
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.
13 | P a g e
Internal Placement Training
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.
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
15 | P a g e
Internal Placement Training
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
16 | P a g e
Internal Placement Training
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
17 | P a g e
Internal Placement Training
18 | P a g e
Internal Placement Training
It is an Equilateral triangle.
It is an Isosceles triangle.
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
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
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).
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
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
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
Input:
Enter the number: 2326
Output:
Reverse of 2326 is 6232
Input:
Enter the number: 3473
Output:
3473 is not a Palindrome
Input:
28 | P a g e
Internal Placement Training
Input:
Enter the number: 16
Output:
16 is a perfect square
Input:
Enter the number: 33
Output:
33 is not a perfect square
Input:
Enter the number: 17
Output:
17 is a prime number
Input:
Enter the number: 16
Output:
16 is not a prime number
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
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.
Input:
Enter the decimal value: 12
Output:
Binary value – 1100
Input:
Enter the binary value: 110
Output:
Decimal value – 12
Input:
Enter the first number: 1095
Enter the second number: 1168
Output:
30 | P a g e
Internal Placement Training
Input:
Enter the first number: 1095
Enter the second number: 1168
Output:
The LCM of 1095 and 1168 is 17520
Input:
Enter the limit: 10
Output:
The first 10 perfect square numbers are 1, 4, 9, 16, 25, 36, 49, 64, 81, and 100.
Input:
Enter the number: 145
Output:
145 is a strong number
Input:
Enter the number: 15
Output:
15 is not a strong number
Input:
Enter the limit: 1000
Output:
31 | P a g e
Internal Placement Training
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
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
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
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
Input:
Enter the number: 153
Output:
153 is a narcissistic number
Input:
Enter the number: 9474
Output:
9474 is a narcissistic number
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
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.
37 | P a g e
Internal Placement Training
52. Write a C program to display the pyramid pattern using the alphabet.
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
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
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
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
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
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
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
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
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
Input:
Enter the limit: 5
Enter the elements: 8 9 6 8 6
Output:
Input values – [8, 9, 6, 8, 6]
Frequency Table
82
91
62
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
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]
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]
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]
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
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”
Input:
Enter the string: Placement
Output:
The word “Placement” has 9 characters.
Input:
Enter the string: Training
Output:
The characters in the given string are: T, r, a, i, n, i, n, g
Input:
Enter the string: company
Output:
Original String – company
Copied string – company
Input:
53 | P a g e
Internal Placement Training
Input:
Enter the string: malayalam
Output:
„a‟ is the character the occurs more number of times in the given string “malayalam”.
Input:
Enter the string: Placement
Output:
Original string – Placement
Reversed string – tnemecalP
Input:
Enter the string: Internal programming training for final years
Output:
Number of words - 6
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
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.
Input:
Enter the limit: 3
Enter the string:
python
c
java
Output:
55 | P a g e
Internal Placement Training
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”
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
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
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
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
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
59 | P a g e
Internal Placement Training
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