0% found this document useful (0 votes)
258 views22 pages

Raptor Tasks

The document contains tasks to write programs that perform basic mathematical and logical operations like addition, subtraction, multiplication, division, checking if a number is even/odd/prime, finding larger of two numbers, etc. It also contains tasks to write programs that take user input, perform operations based on the input and display appropriate outputs. The tasks are divided into three sections and include sample test cases with inputs and expected outputs for each program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
258 views22 pages

Raptor Tasks

The document contains tasks to write programs that perform basic mathematical and logical operations like addition, subtraction, multiplication, division, checking if a number is even/odd/prime, finding larger of two numbers, etc. It also contains tasks to write programs that take user input, perform operations based on the input and display appropriate outputs. The tasks are divided into three sections and include sample test cases with inputs and expected outputs for each program.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 22

SECTION1

Task 1

Write a program to add two integers A and B.

Input
Test case Output
A B

1 20 10 30

2 30 20 50

3 40 20 60

Task 2

Write a program to compute the square of an integer x.

Test case Input X Output

1 2 4

2 6 36

3 5 25

Task 3

Write a program to read the name and print in the following format

Test case Input(Name) Output

1 Charan Hello Charan!!!

2 Vikram Hello Vikram!!!

3 Shanthi Hello Shanthi!!!

Additional Task1

Write a program to compute division by reading dividend and divisor as input and display quotient
Input
Test case Output
dividend divisor

1 20 10 2

2 72 7 10.2857

3 5 20 0.25

Additional Task2

Write a program to compute exponentiation of base and power

e.g: 53 = 5 x 5 x 5

Input
Test case Output
base power

1 5 3 125

2 2 4 16

3 6 8 1679616

Additional Task3

Write a program to print the floor values of the given input X

Test case Input X Output

1 5.23423 5

2 1.8912 1

3 -1.643 -2

SECTION2

Task 1
Write a program to find the bigger of 2 integers A and B.

Input
Test case Output
A B

1 4 19 19

2 101 100 101

3 122 123 123

Task 2

Write a program to check if a given positive integer is even or odd.

Test case Input A Output

1 4 Even

Input should be positive


2 -102
number

3 57 Odd

Task3

Write a program that takes three integers A, B, and C as input. The program should return “Possible”
if it is possible to add two of the integers to get the third one and “Impossible” otherwise

Input
Test case Output
A B C

1 1 2 3 Possible

2 3 7 4 Possible

3 2 3 9 Impossible

Additional Task 1

Write a program that takes two integers A and B and print

         "Large", if sum of A and B is greater than 20.

         "Medium", if sum of A and B is in the range 10 and 20(inclusive).


         "Small", otherwise.

Input
Test case Output
A B

1 11 12 Large

2 7 6 Medium

3 7 2 Small

Additional Task 2

Write a program that takes two integers A and B and checks whether both are “double digit” numbers.
If both are not double digit numbers then return “False” and end the program. If both are double digit
numbers then return "Odd Sum", if sum of A and B is odd and "Even Sum" otherwise.

Input
Test case Output
A B

1 11 100 False

2 12 10 Even Sum

3 30 21 Odd Sum

Additional Task 3

Write a program to simulate the following grade sheet.

Marks Grade

85 and above Excellent


Between 70 and 84 inclusive Good

Between 60 and 69 inclusive Satisfactory

Less than 60 Not satisfactory

You will need to read the marks from the user and display the appropriate grade. Note: Marks can be
between 0     and 100 (both inclusive) only.

Test case Input(Marks) Output

1 82 Good

2 103 Marks should be less than or equal to 100

3 30 Not satisfactory

Additional Task 4

You will need to read two integers and perform the following operations on them based on the user
input (1 - addition, 2 - subtraction, 3- multiplication, 4 - division).

Note: Division should display only the quotient.

Test
Input
case
Output
  A B Operation

1 25 43 1 68

2 32 23 2 9

3 30 3 3 90

0 4 Not
4 56
possible

5 22 11 4 2
SECTION3

Task 1

Write a program that asks the user to input a non-negative number N and prints the first N natural
numbers.

Test case Input(N) Output

1 2 [ 1 2]

2 4 [1 2 3 4]
3 7 [ 1 2 3 4 5 6 7]

Task 2

Write a program to print the first N even numbers.

Test case Input(N) Output

1 4 [ 2 4 6 8]

2 3 [ 2 4 6]

3 1 [2]

Task 3

Write a program to check whether a given positive integer A is a prime number or not.

Test case Input(A) Output

1 11 Prime

2 82 Not a Prime

3 17 Prime

Additional Task 1

Write a program that takes as input three integers, the number whose multiples you need to find, and
the other two numbers, the lower and upper limit between which you need to find the multiples. All
three inputs should be integers.

Input
Test case Output
N Lower limit Upper limit

1 12 0 87 0, 12, 24, 36, 48, 60, 72, 84

2 -4 -9 3 -8, -4, 0

3 A 9 100 Invalid input

Additional Task 2

Write a program to print the multiplication table of an integer (X) till a certain limit (number and limit
to be specified by user). By default the multiplication table starts with 1.
Input
Test case Output
X Limit

3 * 1 = 3 
3 * 2 = 6 
3 * 3 = 9 
3 * 4 = 12

3 * 5 = 15
1 3 10
3 * 6 = 18 
3 * 7 = 21
3 * 8 = 24

3 * 9 = 27

3 * 10= 30

5 * 1 = 5 
5 * 2 = 10 
2 5 5 5 * 3 = 15
5 * 4 = 20

5 * 5 = 25

Additional Task 3

Write a program to print the pattern specified in the test case.

Test case Input(rows) Output

1   2   3

1 3 4   5

1         2
2 2
3
1      2     3     4    5

6      7     8     9

3 5 10   11   12

13   14

15

Additional Task 4

Write a program to find out the square root of a number using only loops and conditions. Do not use in
built functions like sqrt or operations like ** and ^.

In other words, given a positive integer 'x', find the largest positive integer 'n' such that n^2 <= x.

Test case Input(X) Output

1 4 2

2 7 2.6458

3 20 4.4721

Additional Task 5

Write a program to find out if a given positive integer has digits in ascending order or descending
order. You will need to check this from the left most digit to the right most digit.

Test case Input Output

1 123 Ascending

2 986278 Arbitrary

3 987 Descending

4 dkl Invalid Input


SECTION4

Task 1

Write a program to add two arrays A and B of size 5.

Input
Test case Output
A B

1 [-1 2 3 1 4] [2 2 2 2 2] [1 4 5 3 6]

2 [0 0 0 0 0] [1 2 3 4 5] [1 2 3 4 5]

3 [2 5 1 7 3] [3 2 1 -8 0] [5 7 2 -1 3]

Task 2

Write a program to reverse the order of any given integer array A of any size. (Do not use the another
array variable to store the values or just print it in reverse order)
Test case Input(A) Output

1 [1 2 3 4 5 6] [6 5 4 3 2 1]

2 [3 1 2] [2 1 3]

3 [10 1 9 7] [7 9 1 10]

Task 3

Write a program to add two 4X4 matrices A and B and store the result in matrix C.

Input
Test case Output (C)
A B

1 1 1 1 
1 1 1 1 
2 2 2 2 
1 1 1 1   3 3 3 3 
2 2 2 2 
1 1 1 1 1   3 3 3 3 
2 2 2 2 
 3 3 3 3 
2222
 3 3 3 3

1 3 3 2 
3 1 2 3  -2  1  2 2  -1  4  5  4 
3 2 1 3  2  2  3  2    5  3  5  5 
2
2 3 3 1   2  2  4 -2   5  4  5  1 
-6  2  2 -1  -4  5  5  0

Additional Task1

Write a program to read an integer array (of size 10) from the user. Now do the following operations on
the array (user needs to select one of these operations)

1.   Display the array

2.   Reverse the array and display it


3.   Display all odd elements in the array

4.   Display all even elements in the array

Input
Test case Output
Input Array operation

1 [2  4  5  1  3  8  2  7  6  9] 1 [2  4  5  1  3  8  2  7  6  9]

 
2 3 [5  1  3  7  9]
[2  4  5  1  3  8  2  7  6  9]

[2  4  5  1  3  8  2  7  6  9]
3 2 [9  6  7  2  8  3  1  5  4  2]

4 [2  4  5  1  3  8  2  7 6  9] 4 [2  4  8  2  6]

Additional Task2

Write a program to read an integer array, A, of size 5. You will now need to create another array O (of
size 5) which satisfies the following condition.

O[i] = Product of all the individual elements in A excluding the i th element

Eg: O[1] = A[2]*A[3]*A[4]*A[5]

       O[3] = A[1]*A[2]*A[4]*A[5]

Test case Input(A) Output (O)

1 [1  2  3  4  5] [120  60  40  30  24]

2 [2  3  1  2  1] [6  4  12  6  12]

3 [5  1  3 7  2] [42  210  70  30 105]

Additional Task3

Write a program to read a 2-dimensional matrix of order 2x2 and perform the following operations on it

      Transpose of the array


      Determinant of the array

Hint: A = |a     b|    
   |c     d|           
 
Transpose: AT = |a       c|
                 |b      d|
 
Determinant:  |A| = a*d – b*c
 

Test case Input Output (O)

Transpose: |2    1|
|2     3|
1                   |3    4|
|1     4|
Determinant:  5

Transpose: |-2    5|
|-2   -3|
2                   |-3    4|
|5     4|
Determinant:  7

Transpose: |4    1|
|4     -1|
3                   |-1   0|
|1      0|
Determinant:  1
SECTION5

Task 1

Write a program that takes three string inputs S1 (your name), S2 (college name), and S3 (city) and
prints the strings separated by the delimiter comma (,).

Input
Test case Output
S1 (name) S2(College name) S3 (City name)

1 Shyam A R College Mumbai Shyam, A R College, Mumbai

Roy Engineering Kolkata Subhash, Roy Engineering College,


2 Subhash
College Kolkata

3 Sujit IIIT Hyderabad Sujit, IIIT, Hyderabad

Task 2

Write a program that takes a string S1 of letters as input and converts the letters into upper case.

Test case Input - S1 Output

1 Abcdef ABCDEF
2 Hello, how are you? HELLO, HOW ARE YOU?

3 Alpha315ComeIn ALPHA315COMEIN

 Task 3

Write a program that takes two string inputs S1, S2 and checks whether S2 is a substring of S1 or
not.

Input
Test case Output
S1 S2

1 ChanakyaPuri Chaya No

2 India In Yes

3 Panipat pat Yes

Additional Task1

Write a program to reverse a string S1 and stores the result in S2.

Test case Input S1 Output- S2

1 Vikram Markiv

2 Program margorP

3 EnhanceEdu udEecnahnE

Additional Task2

Write a program to find if a given string ‘S’ is a palindrome or not.

Test case Input S Output

1 Civil Not palindrome

2 Madam Palindrome

3 rotator Palindrome

Additional Task3

Write a program to check the order of two strings S1 and S2 in the dictionary i.e which of these strings
appear later in a dictionary.
 

Input
Test case Output
S1 S2

1 Java PHP PHP

2 Rahul Ramesh Ramesh

3 roommate roomy Roomy

Additional Task4

Write a program that reads a large string (minimum length 50) and gives a count of the number of
vowels and consonants in that sentence.

Hint: Use ascii values and check that with vowels’ ascii values

Test
Input Output
case

One of the most important parts of programming is Vowels: 27


1
controlling which statement will execute next Consonants: 53

String minimum
2 Welcome to CT
length should be 50

The algorithm you are developing may need to do Vowel: 31


3
some actions based upon a decision. Consonants: 37

Additional Task5

Write a program that takes a string as input and displays the string after removing the repeated
characters. (Consider lower case character and upper case character is same eg: ‘A’ equals to ‘a’)

Test case Input Output

1     helloworld hewrd

2 Madam d

3 EnhanceEdu hacdu
SECTION6

Task 1

Write a program that takes an integer A as input and calls the function

Large (), if A > 100. This function prints the string “Large”.

Medium (), if 50 <= A <= 100. This function prints the string “Medium”.

Small (), otherwise and it prints string “Low”.

Use subcharts for doing this problem.

Test case Input A Output

1 120 Large

2 50 Medium

3 22 Small

Task 2

Write a program that sends two integers A and B as parameters to different functions below

Sum () prints the sum of A and B.

Product () prints product of A and B.

Diff() prints the difference A - B.

Read the read the operation (1 for Summation, 2 for product and 3 for Difference of A and B) that
needs to be performed by calling the particular function. Use Procedures to solve the problem.
Input
Test case Output
A B Operation

1 5 8 1 13

2 6 2 3 4

3 20 4 2 80

Task3

Write a function to sort the elements in an array (of length 5). You should pass the unsorted array to
this function and the function should return a sorted array. Use Procedure to solve the problem

Test case Input Array Output

1 {2,1,3,4,5} 1,2,3,4,5

2 4,2,1,1,5 1,1,2,4,5

3 5,9,e,2,1 Invalid Input

Additional Task1

Write a program that reads two strings as input and checks if the string in smaller length is a substring of
the larger string. Pass the two strings as inputs to a function checkSubString, which checks if the smaller
string is a substring of the larger one or not.

Input
Test case Output
String1 String2

1 Panipat Pat “String 2 is substring of String1”

2 In India “String1 is substring of String2”

3 a Matrix “Length should be atleast 2”

“String2 is not substring of


4 Robot Bat
String1”

 
Additional Task2

Write a program that reads a 3x3 matrix, “A” as input and performs the following actions on it
a.     Transpose(A)
b.     Determinant(A)
 
Ex: Transpose of 3X3 Matrix
Let Matric A= | a        b          c|
                        |d         e          f|
                        |g         h          i|
 
  AT =   |a         d          g|
             |b        e          h|
             |c         f           i|
 
Ex: Determinant of 3X3 Matrix
 
Let Matric A= | a        b          c|
                        |d         e          f|
                        |g         h          i|
 
|A| = a(ei-hf)+b(fg-di)+c(dh-eg)
 
 
Test case Input A Output
Transpose of matrix:
|1   2    3| |1    4    7|
1 |4   5    6| |2    5    8|
|7   8    9| |3    6    9|
Determinant of matrix: 0
Transpose of matrix:
|-1     5    -2| |-1     4     8|
2 |4      3      6| |5      3     2|
|8      2     -1| |-2     6    -1|
Determinant of matrix: 307
|3    4     4|
3 |4    e     5| Invalid Input
|2    1    6|
 
Additional Task3
Write a program that reads two 2x2 matrices, A and B,  and perform the following functions on them
a.     Addition(A, B) i.e. A + B
b.     Subtraction(A, B) i.e. A - B
c.     Multiplication(A, B) i.e. A * B
 

Ex:
A= | a     b|         B= | e      f|                   A+B =    |a+e        b+f|
      |c      d|               | g     h|                                  |c+g        d+h|
 
A-B = |a-e        b-f|                               A X B =   | (a*e) + (b*g)        (a*f) + (b*h) |
           |c-g        d-h|                                               | (c*e) + (d*g)        (c*f) + (d*h) |
  
Input
Test case Output
A B
Addition:   |-1      8|
                    |5        0|
 
|2     3| |-3     5 | Subtraction:   |5        -2|
1
|3     1| |2      -1|                         |1         2|
 
Multiplication:   |0        7|
                            |-7     14|
|2     e| |-3     5 |
2 “Invalid input”
|3     1| |2      -1|
 

Additional Task4 

Write a program that reads a string as input and performs the following functions based on the user
option to select the following function

1.     toUpper() - converts the string to upper case

2.     charAt(int position) – Displays the character at position in the string

3.     substring(int start, int end) – Displays a substring from start position to end position in the string

Input
Test
Output
case Character Start
String User option End position
position position

1 Welcome to India 1 --NA-- --NA-- --NA-- WELCOME TO INDIA

2 Welcome to India 2 6 --NA-- --NA-- M

3 Welcome to India 3 --NA-- 12 16 India

4 Welcome to India 5 --NA-- --NA-- --NA-- Invalid input

**NA: input not applicable


SECTION7

Task 1

Given a positive integer N as user input, write a program to print the sum of the first N natural
numbers using recursion.

Test case Input N Output

1 3 6

2 5 15

3 10 55

Task 2

Given a positive integer N as user input, write a program to print the sum of the cubes of the first N
natural numbers using recursion.

Test case Input N Output

1 3 36

2 1 1

3 5 225

Task 3

Write a program to find whether the given number P is a prime number or not using recursion.

Test case Input N Output

1 3 "Prime Number"

2 5 "Prime Number"

3 8 "Not A Prime Number"

 
Additional Task1

Write a program that takes a string "Str1" as input and prints the reverse of it using recursion.

Test case Input Str1 Output

1 Arjuna anujrA

2 Ashoka akohsA

3 Reverse esreveR

Additional Task2

Write a program to sort an array recursively

Input
Test case Output
size Array

1 5 {2, 3, 5, 1, 6} {1, 2, 3, 5, 6}

2 1   Array size should be at least 2

3 8 {2, 4, 2, 5, 6, 1, 3, 9} {1, 2, 2, 3, 4, 5, 6, 9}

Additional Task3

Write a program that print first 500 prime numbers using recursion.

You might also like