Question
Name the project as Program1, Program2 for each of the questions in this assignment. Select both question folders, and zip them into ONE folder, name
Name the project as Program1, Program2 for each of the questions in this assignment.
Select both question folders, and zip them into ONE folder, name the zipped folder FirstnameLastNameM2 (i.e. MollySmithM2.zip)
Program1:
Prime numbers are the numbers that only have the divisor of 1 and itself like 2, 3, 5, write a console program to get an input number n from console, and calculate all the prime numbers between [2, n]. Make sure prime numbers are separated by spaces in the output. Follow the following examples for user input, and output format.
Example 1:
5 //input 2 3 5 //output
Example 2:
15 2 3 5 7 11 13
Hint: Dont hard code prime numbers. Your program should work for any integer input in theory. You need to do a prime number test for every number between [2, n], and decide whether its a prime number (add to an prime number collection) or not (discard). There are many prime number algorithm depending on the efficiency, and we have no efficiency requirement for this question, so you could choose a simple one as below.
From Wikipedia: The simplest primality test is trial division: Given an input number n, check whether any integer m from 2 to n evenly divides n (the division leaves no remainder). If n is divisible by any m then n is composite, otherwise it is prime.
https://en.wikipedia.org/wiki/Primality_testLinks to an external site.
Program2:
Write a console program to sort a series of numbers in ascending order. The first line of input should be an integer - indicates the total number of elements to be sorted. For the following line, read each number separated by a space into an array. After sorting the numbers, print the sorted number on the console spectated by a space. Follow the following examples for user input and output format. In Example1, the first line (5) is the total number of elements; the second line contains five input numbers to be sorted, and the third line is the sorted output.
Example1:
5 5 2 3 1 4 1 2 3 4 5
Example2:
6 6.6 5.5 4.4 3.3 2.2 1.1 1.1 2.2 3.3 4.4 5.5 6.6
Note: your program needs to meet the following requirements:
1. Your program needs to handle floating point numbers.
2. Do not use any C# build-in sorting algorithm such as Array.Sort(), write the sorting algorithm yourself.
3. Choose any sorting algorithm you like: bubble sort, selection sort, merge sort, etc.
4. Exception handling is NOT required. You can safely assume a clean input from the console.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started