Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Kindly note that I have asked this question before but the answer was not very logical. Therefore, I had to post it again here: The

Kindly note that I have asked this question before but the answer was not very logical. Therefore, I had to post it again here: The solution must only be provided in pseudocode.

Write a program whose input is an array A of positive numbers and a positive number x. The program should print the smallest element of A that is greater than x. If such an element does not exist, the program should print 1. For example, if A = [1, 3, 5, 3, 6, 5] and x = 3 then the program should print 5. You may not use recursion for this particular task.

I have tried to solve this as follows:

FindNum(A[ ], x)

{

result = A[0]; // kindly note i can not initialise this with a random number therefore I have done so by A[0]

for (i = 0; i < len(A[ ]); i++) {

if ( A[i] > x )

result - A[i]; //this finds a number larger than x but does not satisfy the requirement of finding the smallest number larger than x

}

print (resutl);

}

I believe there should be another variable containing the current value of result and comparing it with the new value and keeping the smaller of two? but I am not sure how to implement it.

Kindly advice.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

=+6. What does a good workplace look like to you?

Answered: 1 week ago

Question

LO42.2 List some of the obstacles to economic development.

Answered: 1 week ago