Knowee
Questions
Features
Study Tools

Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a comma, even the last one. The output ends with a newline.Ex: If the input is:5 25 51 0 200 330 50then the output is:25,0,33,(the bounds are 0-50, so 51 and 200 are out of range and thus not output).To achieve the above, first read the list of integers into a vector.

Question

Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. That list is followed by two more integers representing lower and upper bounds of a range. Your program should output all integers from the list that are within that range (inclusive of the bounds). For coding simplicity, follow each output integer by a comma, even the last one. The output ends with a newline.Ex: If the input is:5 25 51 0 200 330 50then the output is:25,0,33,(the bounds are 0-50, so 51 and 200 are out of range and thus not output).To achieve the above, first read the list of integers into a vector.

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

Here is a Python program that accomplishes the task:

# Read the number of integers
n = int(input())

# Read the integers into a list
numbers = []
for _ in range(n):
    numbers.append(int(input()))

# Read the lower and upper bounds
lower, upper = int(input()), int(input())

# Print the numbers within the range
for num in numbers:
    if lower <= num <= upper:
        print(num, end=',')
print()

This program first reads the number of integers from the input, then reads each integer into a list. It then reads the lower and upper bounds. Finally, it iterates over the list of numbers and prints each number that is within the range, followed by a comma. The end=',' argument to the print function ensures that a comma is printed after each number instead of a newline. The final print() call prints a newline at the end of the output.

This problem has been solved

Similar Questions

Lena is planning a number game for her younger brother, Max. She wants to list all the numbers within a given range that either end in 7 or are multiples of 7. Help Lena by writing a program that takes the lower and upper bounds of the range and prints these special numbers.Input format :The input consists of two space-separated integers L and U, representing the lower and upper bounds of the range.Output format :The output prints the special numbers from the given range (both lower and upper range inclusive), separated by space.Refer to the sample output for formatting specifications.Code constraints :1 ≤ L, U ≤ 150L < USample test cases :Input 1 :7 17Output 1 :7 14 17 Input 2 :23 69Output 2 :27 28 35 37 42 47 49 56 57 6

The program must accept N integers as the input. The program must sort the N integers using selection sort and print all the iterations of the selection sorting process as the output.Boundary Condition(s):2 <= N <= 1001 <= Each integer value <= 1000Input Format:The first line contains N.The second line contains N integers separated by a space.Output Format:The lines containing all the stages of the selection sort.Example Input/Output 1:Input:512 6 15 9 10Output:6 12 15 9 106 9 15 12 106 9 10 12 156 9 10 12 15

Arun is tasked with creating a program that prints prime numbers within a given range. The program should take two integers, start and end, as input, and output the prime numbers between these two values (inclusive).Help Arun to complete the task using a 'for' loop.Input format :The input consists of two space-separated integers L and U, representing the starting range and ending range of the prime numbers.Output format :The output prints the prime numbers from the given starting range to the ending range separated by space.Refer to the sample output for formatting specifications.Code constraints :1 ≤ L, U ≤ 150L < USample test cases :Input 1 :1 23Output 1 :2 3 5 7 11 13 17 19 23 Input 2 :23 69Output 2 :23 29 31 37 41 43 47 53 59 61

Write  a program to print the multiples of given N within the rangeInput FormatThree space separated integers - 'N', 'start' and 'end'Output FormatPrint the multiple of given N within the range.Sample Input 15 1 10Sample Output 15 10 15 20 25 30 35 40 45 50Sample Input 25 10 15Sample Output 250 55 60 65 70 75

Problem Statement:Write a  program to find the sum of numbers in the given range.Input Format:Given two integers start and end ranges separated by SPACE.Output Format:Print the sum in the given range.Constraints1<=start < end <= 1000000NOTE : The calculated sum value might exceed integer range.Sample Input 1:10 20Sample Output 1:165Sample Input 2:1 100Sample Output 2:5050

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.