You are on page 1of 1

Sets - Homework

1. Write a program that prompts the user to enter 10 numbers and then print
all the numbers entered by the user (not in order) as well as the sum of
the numbers. Duplicates will be ignored.
Your program must store the numbers entered by the user in a set.

2. Write a program that prompts the user for 5 numbers and store them in a
set. Duplicates will be ignored. Your program is then required to print
out all the numbers entered and the smallest number entered.

3. Write a program that prompts the user to enter 10 numbers and then
completes the following tasks:
a. Print all the odd numbers in the set
b. Print all the even numbers in the set

Store the numbers in a set. Duplicates will be ignored. Then use the set
to complete the tasks.

Example:
Entered numbers: 0 3 10 12 205 23 100 0 5 11
Odd numbers: 3 5 11 23 205
Even numbers: 0 10 12 100

4. Write a program that prompts the user to enter a set of numbers terminated
by -1 and then completes the following tasks:
a. Print sum of all the even numbers
b. Count the number of odd numbers in the set.

Store the numbers in a set. Duplicates will be ignored.

Example:
Entered numbers: 0 2 3 5 44
Sum of even numbers: 46
Odd number count: 2

5. Write a program that prompts the user to enter a set of numbers terminated
by -1. The program must then print all the numbers entered by the user at
the end of the program and then print the number of numbers entered by the
user and the largest and smallest number within the set. Duplicates will
be ignored. Program should store all the numbers in a set called numbers.

6. Write a program that prompts the user to enter a set of numbers between 0
and 20 (inclusive), terminated by -1. The program must print all the
numbers between 0 and 20 (inclusive) NOT entered by the user. Ensure that
entering a number outside the range of 0 to 20 will not result in an
error.

7. Write a program that prompts the user to enter a set of numbers between 1
and 100 (inclusive), terminated by -1. The program must print all the
numbers (without duplication) that are not prime numbers. Do NOT list all
the primes explicitly in your program. Assume that none of the entered
numbers would be outside the range.

You might also like