You are on page 1of 1

Lab

Exercise 5

1. Given a list containing integers, write code to


(A) Find and print the smallest number in the list
(B) Find and print the index of the smallest number in the list
(C) Find and print the second smallest number in the list
(D) Find and print the index of the second smallest number in the list
(E) Check whether a given number is present in the list or not. If the number is
present then print the index of the number
The list of n integers can be initialized in the code itself.

[searchList.cpp]

2. Write a program which reads two positive integers and , , and finds the th
largest element from amongst real numbers, using an array of size 10.

[kthlargest.cpp]

3. Write a program which reads an integer list , and an integer that is smaller than
(), and finds a subsequence , + 1, , + 1 of length such that the sum
[] + [ + 1] + + [ + 1]
is maximum over all such subsequences of length . The program should print the value
of and the sum. Make your computation as efficient as possible by avoiding repetitive
addition of the same elements.
[maxSum.cpp]

4. Given a list containing integers, write a function to compute and print all the
products of the elements in the list excluding one element at a time. Make your function
recursive. Make your computation as efficient as possible by avoiding repetitive addition
of the same element.
[allButOne.cpp]

You might also like