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
pashok25 [27]
3 years ago
8

Write a program that first gets a list of integers from input. Then, get another value from the input, and output all integers l

ess than or equal to that value. If the input is 5 50 60 140 200 75 100, the output is: 50 60 75.
Computers and Technology
1 answer:
jonny [76]3 years ago
5 0

Answer:

The c++ program for the given scenario is given below.

#include <iostream>

using namespace std;

int main() {

   int len=20, arr[len], data;    

   // initialize all elements of the array to 0

   for(int i=0; i<len; i++)

   {

       arr[i] = 0;

   }    

   cout<<"This program outputs all the numbers less than or equal to the given number."<<endl;

   cout<<"Enter the list of numbers. Enter 0 to stop entering the numbers. "<<endl;

   for(int i=0; i<len; i++)

   {

       cin>>arr[i];        

       // 0 indicates user wishes to stop entering values  

       if(arr[i] == 0)

           break;

       else

           continue;

   }    

   // number from which the list is to be compared

   cout<<"Enter the number to be compared."<<endl;

   cin>>data;

     

   cout<<"The values less than or equal to the number "<<data<<" are "<<endl;

   for(int i=0; i<len; i++)

   {  

       // 0 indicates the end of the list entered by the user

       if(arr[i]==0)

           break;

       if(arr[i] <= data)

           cout<<arr[i]<<endl;

   }    

   return 0;    

}  

OUTPUT

This program outputs all the numbers less than or equal to the given number.

Enter the list of numbers. Enter 0 to stop entering the numbers.  

23

45

67

89

10

0

Enter the number to be compared.

59

The values less than or equal to the number 59 are  

23

45

10

Explanation:

This program takes input only from the user and makes no assumptions.

The list of numbers entered by the user are stored in an array. If the user input is less than the size of the array, the remaining elements are set to 0.

While taking input from the user, if any element of the array is found to be 0, the loop is discontinued.

for(int i=0; i<len; i++)

   {

       cin>>arr[i];        

       if(arr[i] == 0)

           break;

       else

           continue;

   }  

Same test is applied when all the numbers less than the given number are displayed.

for(int i=0; i<len; i++)

   {  

        if(arr[i]==0)

           break;

       if(arr[i] <= data)

           cout<<arr[i]<<endl;

   }

The above program takes into account all the specifications in the given question.

You might be interested in
Write a program that rolls two dice until the user gets snake eyes. You should use a loop and a half to do this. Each round you
marishachu [46]

import random

num_rolls = 0

while True:

   r1 = random.randint(1, 6)

   r2 = random.randint(1, 6)

   print("Rolled: " + str(r1) + "," + str(r2))

   num_rolls += 1

   if r1 == r2 == 1:

       break

print("It took you "+str(num_rolls)+" rolls")

I added the working code. You don't appear to be adding to num_rolls at all. I wrote my code in python 3.8. I hope this helps.

4 0
3 years ago
Which of these statements regarding mobile games is true? A. They are typically played indoors. B. They have detailed environmen
Lyrx [107]

Answer:

c and d

Explanation:

6 0
3 years ago
A buffer storage that improve computer performance by reducing access time is​
kvasek [131]
Cache memory

Hope it helps
4 0
3 years ago
Jason Chang is creating photos of his restaurant for a new website. Some of the photos of the staff have red eye, others are bad
Nadusha1986 [10]

It is okay to modify photos digitally to improve their appearance as long as it doesn't show what they aren't producing.

<h3>What is Advertisement?</h3>

This is the act of persuading people to buy goods and services and is usually done with the aid of the media.

Pictures are usually taken which have to be in the best shape and quality in order to entice people to buy the goods thereby bringing about higher sales and profit for the company.

Read more about Advertisement here brainly.com/question/1020696

7 0
2 years ago
When you use the tilde operator (~ in a url for the attribute of a server control, it represents the _____ directory of the webs
Verizon [17]
The tilde operator represents the root directory of the website.
4 0
3 years ago
Other questions:
  • What is an online alternative to customers sending checks via mail?
    7·1 answer
  • What economic measure is at the highest level since the Great Depression?
    12·1 answer
  • Could this be restored? And is it worth the money it’d take?
    9·2 answers
  • A department store plans to upgrade its IT infrastructure to support a new order-processing application with rich features. The
    13·1 answer
  • Vhich economic impact of computers was mentioned in this lesson?
    6·1 answer
  • Which location-sharing service offers items for users as a gaming component and also allows them to collectively link their chec
    9·2 answers
  • What is the benefit of the load balancing logic to end-user?
    15·1 answer
  • What goals do you set for yourself while studying?
    9·2 answers
  • Which of these lines of code will increment a variable?
    11·1 answer
  • Aisha designed a web site for her school FBLA club and tested it to see how well it would resize on different systems and device
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!