Question no 1:

Write a C++ program which declares an array of size N, asks the user to fill the array with

numbers. Your programs will then do two things:

1. First, your program will replace the duplicate elements from the array. For example,

let’s say the size of array is 10, and the numbers user entered are 6, 8, 3, 5, 5, 0, 3, 9, 8,

3. Now after removing the duplicate numbers, the array will become 6, 8, 3, 5, -1, 0, -1, 9, -1, -1. All duplicate elements are replaced with -1. (Assume that the user never gives -

1 as input for the array)

2. In the second part, your program will shift all -1s toward the end of the array. 6, 8, 3, 5,

0, 9, -1, - 1, -1, -1.

3. Provide DRY RUN for both Above part on page


QUESTION NO 2:

Write a C++ program that has an integer array of size N. The array contains N integers. You can hardcode

the elements of the array. Now the program will ask the user to enter an integer number. Your program

will tell whether the number given by the user is the summation of any three numbers in the array. Also

print the three numbers whose sum is equal to the given number.

For example, if the array is: 9, 4, 54, 23, 54, -23 0, 54, 5, 8 and the number entered by the user is 86,

then your program will print 9, 54 and 23. It is possible to have more than one triplet whose summation

equals the given number.

In this case, print all triplets. Such as, if the user enters 85, then the program will print:

a) 54, 23, and 8

b) 54, 54, and -23

c) Also Provide DRY Run for above Program

Post a Comment

0 Comments