Question

In: Computer Science

3. Write a script that generates two random numbers between -5 and 25, calculates their average,...

3. Write a script that generates two random numbers between -5 and 25, calculates their average, and if the average is greater than 10 then prints “High Average” else prints “Low Average”. You can use $RANDOM to generate the random numbers.

4. Write a script using the for-loop construct that counts the number of directories looping through the files in the directory name provided by the user on a prompt by the script.

Solutions

Expert Solution

Answer 3
*************

#!/bin/bash
for (( i=1;i<=5;i++ ))
do
number=`seq -5 25 | sort -R | head -n 1`
array+=("$number")
echo $number
done

avg()
{
for n in ${array[@]}
do
(( total += n ))
done
echo "Total is: "$total
avg=`echo "$total / 5" | bc -l`
echo "Average is: "$avg
}
avg

Answer 4
***********

#!/bin/bash
OLD_IFS="$IFS"
IFS=$'\n'

echo "Enter Directory name: "
read fn

for dir in $(find $fn -maxdepth 1 -type d | sort);
do
  
files=("$dir"/*)
printf "%5d,%s\n" "${#files[@]}" "$dir"
done
FS="$OLD_IFS"

if you have any doubt then please ask me without any hesitation in the comment section below , if you like my answer then please thumbs up for the answer , before giving thumbs down please discuss the question it may possible that we may understand the question different way and we can edit and change the answers if you argue, thanks :)


Related Solutions

Write a R script that calculates the mean and variance of two random variables X~F(m=2,n=5) and...
Write a R script that calculates the mean and variance of two random variables X~F(m=2,n=5) and Y~F(m=10,n=5) from their density functions.
C++. Write a program that generates a random number between 5 and 20 and asks the...
C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses the user makes until...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and...
Random Number Guessing Game C++. Write a program that generates a random number between 5 and 20 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display Too high. Try again. If the user’s guess is lower than the random number, the program should display Too low, Try again. The program should use a loop that repeats while keeping a count of the number of guesses...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the...
Bash script: Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result. Submit your program as LastName_FirstName.sh file.
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into...
In Assembly Language Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers...
In Assembly Language MASM Write a program that generates 10 random numbers (0~99). Save the numbers into arrayInt and calculate the sum. .data arrayInt Byte 10 DUP(?) Displays the array and the sum as follows: The random numbers are: xx xx xx xx xx xx …. The sum is   xxxx
Create a bash script that takes numbers as parameters, calculates sum and prints the result. If...
Create a bash script that takes numbers as parameters, calculates sum and prints the result. If no parameters passed, prompt a user (only one time) to enter numbers to sum and print the result.
Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the...
Create a program RandomFile.java that generates files with random numbers/characters. You are required to write the following three methods in the class RandomFile: ​public static void randomBinaryFile(String fileName, int length) ​public static void randomNumberFile(String fileName, intlength) ​public static void randomCharFile(String fileName, int length) The parameter “fileName” specifies the file name, and “length” specifies the length of the sequence in the file. ● randomBinaryFile will generate a file containing a sequence of 0 or 1 of the specified length; ● randomNumberFile...
In Excel, the RAND function generates random numbers between 0 and 1 compute the expectation and...
In Excel, the RAND function generates random numbers between 0 and 1 compute the expectation and Standard deviation. Hints a = 0 , b = 1 P(x1<= X <= x2) = F(x2) - F(x1)
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them...
****java*** Create an application that generates 20 random numbers between 1 and 100 and writes them to a text file on separate lines. Then the program should read the numbers from the file, calculate the average of the numbers, and display this to the screen.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT