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

Problem Set 5 - Problems On Arrays

The document discusses 21 problems related to arrays. The problems involve taking integer or floating point numbers as input in arrays, performing operations like reversing, summing, averaging, searching, and set operations on the array elements, and outputting the results. The problems cover basic to advanced concepts and are rated based on difficulty levels from * to ***.

Uploaded by

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

Problem Set 5 - Problems On Arrays

The document discusses 21 problems related to arrays. The problems involve taking integer or floating point numbers as input in arrays, performing operations like reversing, summing, averaging, searching, and set operations on the array elements, and outputting the results. The problems cover basic to advanced concepts and are rated based on difficulty levels from * to ***.

Uploaded by

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

Array related problems (total 21 questions)

SL Problem statement Difficulty


levels
1. WAP that will take n integer numbers into an array, and then print all the integers into *
reverse order (from the last valid index to index 0).

Sample input Sample output


5 5 4 3 2 1
1 2 3 4 5
6 1 0 9 3 8 2
2 8 3 9 0 1

2. WAP that will take n integer numbers into an array, and then sum up all the integers in *
that array.

Sample input Sample output


5 15
1 2 3 4 5
6 23
2 8 3 9 0 1

3. WAP that will take n integer numbers into an array, and then sum up all the even integers in that *
array.

Sample input Sample output


5 6
1 2 3 4 5
6 10
2 8 3 9 0 1

4. WAP that will take n floating point numbers into an array, and then find the average of those *
numbers.

Sample input Sample output


5 5.36
1.2 5.6 10.3 4.5 5.2
8 8.38
2.1 8.3 3.7 9.2 0.6 1.5 6.4 10.1

5. WAP that will take n integer numbers into an array, and then sum up all the even indexed *
integers in that array.
Sample input Sample output
5 9
1 2 3 4 5
6 5
2 8 3 9 0 1

6. Wap that will take n integer numbers in an array, n different integer numbers in a second
array and put the sum of the same indexed numbers from the two arrays in a third array.

Sample input Sample output


5 3 10 6 8 13
12345
28348
8 7 9 7 17 9 4 7 15
2 8 3 9 0 1 6 10
51489315

7. WAP that will take n integer numbers into an array, and then reverse all the integers **
within that array. Finally print them all from 0 index to last valid index.

Sample input Sample output


5 5 4 3 2 1
1 2 3 4 5
6 1 0 9 3 8 2
2 8 3 9 0 1

8. WAP that will take n integer numbers into an array, and then find the maximum - **
minimum among them with its index position.

Sample input Sample output


5 Max: 5, Index: 4
1 2 3 4 5 Min: 1, Index: 0
6 Max: 9, Index: 3
2 8 3 9 0 1 Min: 0, Index: 4

9. WAP that will take n alphabets into an array, and then count number of vowels in that *
array.
Sample input Sample output
7 Count: 5
AKIOUEH
29 Count: 13
UNITEDINTERNATIONALUNIVERSITY

10. WAP that will take n integers into an array, and then search a number into that array. If *
found then print its index. If not found then print “NOT FOUND”.

Sample input Sample output


8 FOUND at index position: 3, 7
78132643
3
8 NOT FOUND
78132643
5
11. WAP that will take n integers into an array A, and then copy all numbers in reverse order *
from array A to another array B. Finally show all elements of both array A and B.

Sample input Sample output


8 Array A : 7 8 1 3 2 6 4 3
78132643 Array B : 3 4 6 2 3 1 8 7
3 Array A : 3 2 1
321 Array B : 1 2 3

12. WAP that will take n integer numbers as input in an array and then insert a number in a **
position specified by the user in the array.

Sample input Sample output


10 9 11 34 23 78 16 15 2 37 89 54
9 11 34 23 16 15 2 37 89 54
number: 78 position: 4
5 16 32 14 9 48 6
32 14 9 48 6
number: 16 position: 0
13. WAP that will take n integer numbers as input in an array and then delete a number from *
a position specified by the user in the array.

Sample input Sample output


10 9 11 34 23 15 2 37 89 54
9 11 34 23 16 15 2 37 89 54
position: 4
5 14 9 48 6
32 14 9 48 6
position: 0
14. WAP that will first take n integers into an array A and then m integers into array B. Now **
swap all elements between array A and B. Finally show all elements of both array A and B.

Sample input Sample output


8 Array A : 3 2 1
78132643 Array B : 7 8 1 3 2 6 4 3
3
321

15. WAP that will take n positive integers into an array A. Now find all the integers that are *
divisible by 3 and replace them by -1 in array A. Finally show all elements of array A.
Sample input Sample output
8 7 8 1 -1 2 -1 4 -1
78132643
3 -1 2 1
321

16. WAP that will take n positive integers into an array A. Now find all the integers that have
an odd index and replace them by 0 in array A. Finally show all elements of array A.

Sample input Sample output


8 70102040
78132643
3 301
321

17. WAP that will take n integers into an array A. Now sort them in ascending order within ***
that array. Finally show all elements of array A.
Reference: http://en.wikipedia.org/wiki/Bubble_sort

Sample input Sample output


8 1 2 3 3 4 6 7 8
78132643
3 1 2 3
321
18. WAP that will take n integers into an array A. Now remove all duplicates numbers from **
that array. Finally print all elements from that array.

Sample input Sample output


8 281364
28132643
3 3
333
4 6789
6789

19. WAP that will take n integers into array A and m positive integers into array B. Now find **
the intersection (set operation) of array A and B.

Sample input Sample output


8 1263
78152643
6
136092
3 Empty set
123
2
45

20. WAP that will take n integers into an array A and m positive integers into array B. Now **
find the union (set operation) of array A and B.

Sample input Sample output


8 7815264309
78152643
6
136092
3 12345
123
2
45
21. WAP that will take n integers into an array A and m positive integers into array B. Now **
find the difference (set operation) of array A and B or (A-B).

Sample input Sample output


8 7854
78152643
6
136092
3 123
123
2
45

You might also like