Question

Write a PowerShell script which takes 6 command-line arguments, reverses the digits in each, and then...

Write a PowerShell script which takes 6 command-line arguments, reverses the digits in each,

and then sorts the results.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please refer to the screenshot of the code to understand the indentation of the script and output

Powershell Script

#declare i variable
$i=0
#declare array number to store command line arguments
$number=@()
#declare array to store reversed digits
$reversednumber=@()
#declare variable reversed
$reversed=0
#declare variable digit
$digit=0

#for loop to store arguments in the array number
for($i=0;$i -lt 6;$i++)
{
#store each argument in an array
$number+=$args[$i]
}
#for loop to reverse digit in each arguments
for($i=0;$i -lt 6;$i++)
{
#store by index in num variable
$num=$number[$i]
# while loop runs untill num is not equal to 0
while($num -ne 0)
{
#% modulos operator to find the remainder   
[int]$digit = $num % 10
#multiply reversed by 10 and digit
[int]$reversed = ($reversed *10) + $digit
#divide the number by 10
#Math floor function is used as division in powershell return nearest whole number
[int]$num=([Math]::Floor($num/10))
}
#add the reversed number to reversednumber array
$reversednumber+=$reversed
#again intialize reversed to 0
$reversed=0
}
#used sort to sort the array in ascending and prints here
$reversednumber|sort

Powershell script screenshot

Output Screenshot

Add a comment
Know the answer?
Add Answer to:
Write a PowerShell script which takes 6 command-line arguments, reverses the digits in each, and then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a bash shell script to print the number of command line arguments and list of...

    Write a bash shell script to print the number of command line arguments and list of command line arguments 3. 12]

  • Write a Bash script called hello that uses command line arguments to allow the user to...

    Write a Bash script called hello that uses command line arguments to allow the user to put two strings after the command name, when the script is being executed. These strings should represent a first and last name. The script should then write out a greeting to the user that includes the first and last name. Here is an example of how the script might work (the first line represents what the user types to launch the script): [user@HAL] hello...

  • write the bash script Write a script compress_large_files.sh. This script accepts one or more command line...

    write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...

  • After reading pages 330 - 336, write a program that takes two command line arguments which...

    After reading pages 330 - 336, write a program that takes two command line arguments which are file names. The program should read the first file line by line and write each line, in reverse order, into the second file. The program should include a "usage" method that displays the correct command line syntax if two file names are not provided. Example: if my input file says Hello, World! then my output file will contain !dlroW ,olleH Hints: Use CaesarCipher...

  • Write a script using simple shell commands. The script takes a command line argument that specifies...

    Write a script using simple shell commands. The script takes a command line argument that specifies a directory dir. The script first changes directory to dir, then prints the following in sequence: (a) A line starting “Current date and time: ”. Then on the same line, the current time and date. (b) A line starting “Current directory is : ”. Then, on the same line, the absolute pathname of the current working directory. (c) An empty line (d) The line...

  • Exercise 2: Challenge Exercises 1. Write a Powershell script to Check If a Service is Installed...

    Exercise 2: Challenge Exercises 1. Write a Powershell script to Check If a Service is Installed and Working 2. Write a Powershell to Checks If a File Exists 3. Write a Powershel lfind all the dlls under the Windows folder 4: Write a script sorting process by their start time 5: Write a script to find all files last modified before a certain date. 6: Write a script to find the event log entries that occur most frequently. 7: Write...

  • PYTHON (Triangle Inequality) Write a program triangle.py that takes three integers as command-line arguments and writes...

    PYTHON (Triangle Inequality) Write a program triangle.py that takes three integers as command-line arguments and writes True if each one of them is less than or equal to the sum of the other two and False otherwise. Note: this computation tests whether the three numbers could be the lengths of the sides of some triangle.

  • calculator: Write a program that takes three command-line arguments: number operator number and performs the required...

    calculator: Write a program that takes three command-line arguments: number operator number and performs the required operation and prints the result on a single complete line in standard output. (The four operators of a arithmetic, + * - /, must be recognized here.) please use C++

  • Write a PowerShell script. Make sure to: Comment your script by including your name, date, and...

    Write a PowerShell script. Make sure to: Comment your script by including your name, date, and short description what the script does The script receives two arguments/parameters, first one should be a string and the second one an integer number. Both should be passed to the script as (positional) arguments/parameters Check if there are two passed parameters Check if passed parameters are as expected (check if first is string and secondis integer). You can use param() here. Displays on the...

  • Programs/scripts 13. Write a bash shell script that displays the date by using the shell command...

    Programs/scripts 13. Write a bash shell script that displays the date by using the shell command date. 14. Write a command line program that takes a number and a command as arguments. Call that command that number of times. For example, if your program name is "test" test 3 dir <shows directory> dir <shows directory> dir <shows directory>

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT