4.Arrays_1
4.Arrays_1
Practices# :4
Topic : Arrays
Level 1: Easy
1. Create an integer array with size 5, then fetch the values from the keyboard, store them
in the array, and display the elements.
Input format
The first line of each test case consists of elements of the array
Output format
Constraints
Use a one-dimensional array to store array elements and print the same as the output.
Input 13578 12 14 15 8 99 24 88 67 10 56
Output 13578 12 14 15 8 99 24 88 67 10 56
2. Richard has to read n number of values in an array and he needs to print them in reverse
order
Input format
The first line of each test case consists of the size of the array
The second line of each test case has elements of the array to perform the reverse task
Output format
Constraints
Use a one-dimensional array to store array elements and reverse them by accessing the array
index position.
Input 1 4 5 3
Input 2 2 3 5 18 2 8 97 75 99 76 37 2
Output 18 5 3 2 99 75 97 8 2 2 37 76
3. Create an array of integers, then find and print the size (number of elements) of the array.
Input Format:
Output Format:
Constraints:
Output 5 4 6
4. John has been given an integer array of numbers, his task is to read the integer numbers
from the console and store them into an array then print the sum and average of array
elements as output.
Input format
The first line of each test case consists of the size of the input array elements
The second line of the input consists of elements to be stored in the array
Output format
Constraints
Get input in the integer format. Use a one-dimensional array to store and compute the sum.
Input 1 3 4 5
Input format
The first line of each test case consists of salaries of employees in integer.
Output format
Constraints
Use one dimensional array to store employee salaries and do selection using if- else
statement.
Cases
Input 1 Salary of Emp 1 :12000 Salary of Emp1 :1000 Salary of Emp 1 :1000
Output 2 3 NIL
6. Given are the marks obtained by ‘n’ students in Mathematics subject as integer input and
your work is to count the number of students who obtained mark greater than 70. Also count
the number of students who are failed. (<35).
Input format
Output format
Print the number of students as per condition specified where marks >70 and marks <35
Constraints
Use one dimensional array to store student marks salaries and do selection using if- else
statement.
Input 1 3 4 5
Input 2 78 85 90 25 89 97 75 100 98 76 37 23
Output 3 3 3
NIL 1 2
7. Rita has to initialize an array with int, float or double data type elements and she has to
calculate the number of elements in the array.
Output format
Constraints
Use one dimensional array to store array elements and sizeof function to display the length.
Sample test Cases:
-5.22234
Output 5 4 3
8. Alice has one array with N number of elements and he has to copy all the elements in first
array to second array and print the second array.
Input format
The first line of each test case consists of first array elements.
Output format
Constraints
Get first line input N in the integer format. Use one dimensional array to store array elements
Input 10 12 8 25 99 3 13 29 7
Output 10 12 8 25 99 3 13 29 7
9. Dany has an assignment to print the alternate elements of the input array Arr which is
given to him during the run time of the program.
Input format
The first line of each test case consists of input elements of array
Output format
Constraints
Input 2 4 6 9 3 7 12 1 3 6 2 4 8 0 12 44 15 44 88 21 2 8
Output 2 6 3 12 1 6 4 0 44 44 21 8
10. The challenge for Lisa is to determine the minimum element and maximum element in
the array N given the size and number of elements as input.
Input format
Output format
Constraints
Input 1 4 8 5
11. You are tasked with analyzing the scores submitted by participants in a coding
competition. The objective is to count how many participants achieved each distinct score.
Input Format:
Output Format:
Print each distinct score along with the count of participants who achieved that score in the
format: score: count.
Constraints:
Input 90 85 90 75 85 100 60 70 70 80 60 90 80 45 55 45 60 70 55 80
90 60 45
80: 1
12. Elsa must accept 'n' numbers, store all prime numbers in an array, then print those
numbers as output.
Input format
The first line of each test case consists of array size as limit
The second line of input has the array elements as non- negative numbers
Output format
Constraints
Input 1 4 5 7
Input 2 12 23 29 18 3 7 9 12 2 19 25 57 73 98 50 35
Output 23 29 372 19 73
13. You are tasked with identifying anomalous packet types in a network traffic monitoring
system. In an array of integers representing packet types, all types appear an even number
of times and appear an odd number of times. Your goal is to find and print the anomalous
packet type.
Input Format:
Output Format:
Constraints:
There will always be exactly one packet type that appears an odd number of times.
12
Output 134 8 12
14. You are managing an online survey where users rate various products. After collecting
the ratings, you notice that some products received ratings an odd number of times, while
others received them an even number of times. Your task is to identify which product(s)
received ratings an even number of times.
Input Format:
The second line contains n integers where each integer represents the rating count for a
product.
Output Format:
Input 5 4 6
Level 2: Medium
1. Given a list of N elements and a key K. Find whether the given key exists in the list or not.
If it exists, print its position in the list.
Input format
The first line of each test case consists of size of the array
The third line of each test case consists of integer key K to be searched
Output format
Print the position, if integer is present in the list else print NOT FOUND
Constraints
1 < = N < = 100
Sample test Cases:
Input 1 5 6 4
Input 2 1 2 5 6 10 33 47 19 10 28 99 10 20 30 40
Input 3 5 6 20
2.Rahul has a set of integer input elements that are stored in an array, he has to find the first
and second largest element in a given array list of N numbers. Help him to derive the needed
result.
Input format
The first line of each test case consists of size of the array
Output format
Print the first and second largest array elements
Constraints
1 < = N < = 100
Input 1 5 4 3
Input 2 91 22 54 64 100 20 87 45 67 55 10 99
Output 100 91 87 67 99 55
3. Given an integer array of numbers, your objective is to count distinct element in the given
array.
Input format
The first line of each test case consists of input array elements
Output format
Print the count of the distinct array elements
Constraints
Compare the elements using selection and repetition statements.
10, 20
Output 5 4 5
4. Lina has stored few elements to an array and she has to traverse through the list and print
the number of positive and negative values present in the array as < 0, >0
Input format
The first line of each test case consists of size of the array
Constraints
Traverse through array elements using nested for loop.
Input 1 4 5 3
Output 22 32 21
5. Given an array with N elements as input at the run time, your code should insert an element
at ith location of the list, then all elements from the right of i+1 th location have to be shifted
one step towards right.
Input format
The first line of each test case consists of size of the array
The third line of each test case has the location and the value to be inserted.
Output format
Print the resultant array after insertion operation.
Constraints
Traverse through array elements and insert array value such that 1<=N<=100.
Sample test Cases:
Input 1 4 5 3
Input 2 12 88 90 45 8 9 10 12 15 22 19 30
Input 3 1 10 3 35 2 35
Output 10 12 88 90 45 8 9 35 10 12 15 22 35 19 30
6. Riya has a set of integer input elements and the position at run time by the user. Your task
is to create a program to delete an element at a desired position from an array.
Input format
The first line of each test case consists of input array elements
The second line of each test case consists position(index) of the element to be deleted.
Output format
Print array elements after deletion with their current index position
Constraints
1 < = N < = 100
Input 1 4 3 5
Input 2 15 19 9 10 18 99 34 66 99 12 78 23
Input 3 2 1 4
Output 15 19 10 18 34 66 99 12 78
7. Deena’s task is given for receiving input array elements and sorting those elements into
ascending order.
Input format
The first line of each test case consists of size of the array
Output format
Print the elements in ascending order
Constraints
Input elements should contain both positive and negative numbers.
Input 1 4 5 3
8. Given an array arr with input integer elements, these elements should have combination
of non-negative numbers and negative number. Your task is to arrange the numbers in non-
increasing order.
Input format
The first line of each test case consists of size of the array
Constraints
Input numbers should contain both positive and negative numbers.
Input 1 7 5 4
9.Rihan has a set of natural numbers that are stored to one dimensional array and his
objective is to separate odd and even numbers in two separate arrays
Input format
The first line of each test case has number of elements to be stored in array
Output format
First line of output should have the odd numbers of the array
Second line of output should have the even elements of the array.
Constraints
Compute modulo function to sort odd and even numbers
Input 2 185 23 55 99 76 45 12 89 33 29
Output 15 23 83 45 10 12
8 55 99 83 45
10 12
10. Given an array arr[] of size N-1 with integers in the range of [1, N], the task is to swap
adjacent elements of a one dimensional array.
Input format
The first line of each test case consists of size of the array
Output format
Print the elements in array after swapping.
Constraints
Input elements has the range [1.N]
Input 1 5 4 7