1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Assoli18 [71]
3 years ago
15

1. Let L be a list of numbers in non-decreasing order, and x be a given number. Describe an algorithm that counts the number of

elements in L whose values are x (English description 5 points + Pseudocode 5 points). For example, if L = {1.3, 2.1, 2.1, 2.1, 2.1, 6.7, 7.5, 7.5, 8.6, 9.0} and x = 2.1 then the output of your algorithm should be 4.
Mathematics
1 answer:
e-lub [12.9K]3 years ago
8 0

Answer:

Algorithm

Start

Int n // To represent the number of array

Input n

Int countsearch = 0

float search

Float [] numbers // To represent an array of non decreasing number

// Input array elements but first Initialise a counter element

Int count = 0, digit

Do

// Check if element to be inserted is the first element

If(count == 0) Then

Input numbers[count]

Else

lbl: Input digit

If(digit > numbers[count-1]) then

numbers[count] = digit

Else

Output "Number must be greater than the previous number"

Goto lbl

Endif

Endif

count = count + 1

While(count<n)

count = 0

// Input element to count

input search

// Begin searching and counting

Do

if(numbers [count] == search)

countsearch = countsearch+1;

End if

While (count < n)

Output count

Program to illustrate the above

// Written in C++

// Comments are used for explanatory purpose

#include<iostream>

using namespace std;

int main()

{

// Variable declaration

float [] numbers;

int n, count;

float num, searchdigit;

cout<<"Number of array elements: ";

cin>> n;

// Enter array element

for(int I = 0; I<n;I++)

{

if(I == 0)

{

cin>>numbers [0]

}

else

{

lbl: cin>>num;

if(num >= numbers [I])

{

numbers [I] = num;

}

else

{

goto lbl;

}

}

// Search for a particular number

int search;

cin>>searchdigit;

for(int I = 0; I<n; I++)

{

if(numbers[I] == searchdigit

search++

}

}

// Print result

cout<<search;

return 0;

}

You might be interested in
What are shaped that can classify with these
ella [17]

Answer:A.) triangular prism B.) triangular-based pyramid

Step-by-step explanation:

5 0
3 years ago
A rope has knots every 47 feet 3 inches. what length is this in feet?
nadezda [96]
12 inches = 1 foot

thus 47 feet 3 inches = (47+3/12) feet =47.25 feet
3 0
3 years ago
Read 2 more answers
Which rate has the same unit rate as 126 miles in 9 hours.
OLEGan [10]

Answer: THE ANSWER IS C

Step-by-step explanation:

5 0
3 years ago
What is the solution of 3/x+8 = -4?<br> 20
Evgen [1.6K]

Answer:

x = -1/4

Step-by-step explanation:

3/x = -4 - 8

3/x = -12

x= -3/12

x= -1/4

5 0
3 years ago
Evaluate the expression 8x for x=2
kodGreya [7K]

Answer:

16

Step-by-step explanation:

8x2

5 0
2 years ago
Read 2 more answers
Other questions:
  • Identify the length of BP. PLEASE HELP ASAP!!
    8·2 answers
  • If i clock out at 11:53 and i have 30 Minutes what time do i get in?
    7·2 answers
  • 4b×3b-2b=102 what is b
    8·2 answers
  • What was the temperature
    12·2 answers
  • What does percentage means
    12·2 answers
  • it cost $102.50 to repair a plasma tv. if you pay $15 for new parts and $25 per hour for labour, how much time did it take to re
    5·1 answer
  • (1) 4p²q : 10pq²
    5·1 answer
  • What is the slope of the line that contains these points? x- 31, 36,41,46 y- 10,8,6,4
    13·1 answer
  • Question 2 I don’t really understand it at all
    6·1 answer
  • (04.01 LC)<br><br> 2174<br><br> Evaluate<br><br> (5 points)
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!