Question: 1 Write an extreme version of the Hello World program. Write the following function, which prints Hello, World! to the screen once: static void PrintGreeting()
1
Write an extreme version of the Hello World program. Write the following function, which prints Hello, World! to the screen once:
static void PrintGreeting()
Now, create an indefinite loop that simply calls your function over and over again each loop iteration. Note that you will have to hard kill this program since there is no stopping condition to your loop.
2
Write a power function which computes one value raised to the power of another and then returns the result (i.e. f(base, exp) = base exp ). The function header should look like this:
static int Power(int x, int exp)
Now, outside the function, perhaps in Main, ask the user for both a base and an exponent, with input validation, and call the function passing those inputs as arguments. Catch the return value of the function and display it on the screen.
3
Write a function to convert degrees to radians. This function is useful because most System.Math library functions take radians as arguments, not degrees. Use the following conversion formula:
radians = degrees * / 180.0
Once written, ask the user for some degrees, call your function to convert, and then display the result.
4
Create a function to calculate a factorial. First, use input validation to ask the user for an integer, ensuring the user does not enter a negative value, floating-point value, or non-numeric text. After the input validation, pass the integer to your function and within the function write a for loop to start the counter at the user's input, run as long as the counter is greater than or equal to 1, decreasing the counter by 1 each time. Within the loop, multiply the counter variable into a product variable that starts at 1 (product *= i). Have the function return the factorial product. Main should display the final answer.
5
Write a program to display the multiples of a number up to another number (thus the second number should be greater than or equal to the first number). The function itself should start at the first number and loop until reaching the second number. The function header should look like this:
static void Multiples(int number, int max)
Outside the function, ask the user for two numbers, storing them into integer variables. Then call your function sending the user's numbers as inputs.
6
Write a program to detect if a number is prime or not. Create a function that takes a number in as input, detects if it is prime, and then returns a boolean indicating if the number is prime or not. There are various ways to check if a number is prime, though the easiest way (to understand) is to simply loop through all values from 2 (number / 2), inclusive, and see if any of those values divide evenly into the number. If none of those values divide evenly into the number, then the number is prime.
Example Output
Enter a number to detect primality: 7
7 is prime!
Enter a number to detect primality: 38
38 is not prime!
7
Pick any one of your previous labs (from a previous day) and rewrite it, but this time use functions wherever you can to make your code more modular and maintainable.
8
Write a function to rotate a list of numbers in place, meaning given an array of numbers as input, it rotates them left or right in the same array. If rotating an array of numbers to the right, the numbers that fall off the end of the array are moved to the beginning of the array. If rotating an array of numbers to the left, the numbers that fall off the beginning of the array are moved to the end. See the Example Output. The function header should look like this:
static void Rotate(int[] list, int places, bool left)
Once you write the function, test it by generating an array of 10 random numbers between 0 and 99, and then pass the array to the function to rotate it some number of places either left or right. Then display the array of numbers again. You could even ask the user how many places theyd like to rotate the array, and in which direction, to make the program more dynamic/useful.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
