Question

       Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs...

  1.        Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs to take two inputs like “6-1.sh a b”, and outputs the result of “ab”. Note: You need to implement it, DO NOT use the exponentiation operation provided by the Linux.

  1.        Write a shell script “6-2.sh” to calculate the factorial of a number using while loop. This script needs to take one input like “6-2.sh a”, and outputs the result of “a!”.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Exponential.sh

# to calculate the power of a number
a=4
b=3
count=1
ans=1
  
if[ $b -eq 0 ]
then
ans=1
fi
  
if[ $a -eq 0 ]
then
ans=0
fi
  
if[ $a -ge 1 -a $b -ge 1 ]
then
while[ $count -le $b ]
do
ans= `expr $ans \* a`
count= `expr $count + 1`
done
fi
echo "The Result is $ans"
}

Factorial.sh

# to calculate the factorial of a number
n=$1
a=n
fact=1
while [ $a -gt 1 ]
do
fact=`expr $fact\* $a`
a=’expr $a – 1’
done
echo "Result is $fact"

Add a comment
Know the answer?
Add Answer to:
       Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs...
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
  • Please write a bash script for the following two questions, thank you.    Write a shell script...

    Please write a bash script for the following two questions, thank you.    Write a shell script “6-1.sh” to calculate the exponentiation using while loop. This script needs to take two inputs like “6-1.sh a b”, and outputs the result of “ab”. Note: You need to implement it, DO NOT use the exponentiation operation provided by the Linux.    Write a shell script “6-2.sh” to calculate the factorial of a number using while loop. This script needs to take one input...

  • in Linux, BASH Shell Write a while loop script called count that counts and prints the...

    in Linux, BASH Shell Write a while loop script called count that counts and prints the numbers 0 thru 9 without issuing a new line after each output.

  • USING Unix/Linux shell !!!: 1) Write a script (project2.sh) that will take information from a file,...

    USING Unix/Linux shell !!!: 1) Write a script (project2.sh) that will take information from a file, and print (user’s choice of printers) identical form letters to each recipient. Either E197, E-199, E-194 printers or to project2.output. Prompt the user for their choice. 2) The script and output file are due: per Moodle timeline. Please upload your fully functioning script (project2.sh) your data file (project2.input) and your output file (project2.output) into Moodle. 3) Requirements of the script. a. You can use...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

    SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...

  • Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a....

    Copy/Paste your script from 5b here. 4. Let's look at a more complicated script executable. a. Write the following as script6.sh and change its permissions to count for num in d do if num eq 100 then count (count+1) done echo The number 10 was found $count times What is the output? Run the script as ./script6.sh 10 20 30 10 40 20 50 10 60 <enter Summarize what the script does r using the read command. The following script...

  • THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that...

    THE CODE NEEDS TO BE ON MATLAB 2. Exercise (a) Let's write a script file that calculates exp(2) by a Maclaurin series using a while loop exp x )=-+-+-+-+ The while loop should add each of the series terms. The program error as defined below is smaller than 0.01. Error is the exact value (i.e. exp(2)), minus the approximate value (i.e., the current series sum) should exit the loop when the absolute absolute error-lexact-approx Use fprintf within the loop such...

  • Task 2 Write a shell script program call cal3.sh to do the following. 1. Print the...

    Task 2 Write a shell script program call cal3.sh to do the following. 1. Print the output "you must provide at least one month" when there is no argument 2. Print the calendar with specified month matching the argument when there is one argument $ ./cal3.sh 1 January 2016 Su Mo Tu We Th Fr Sa 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 27...

  • Homework No.2 CSC 222 Write a shell script program called "countf.sh" that will count how many...

    Homework No.2 CSC 222 Write a shell script program called "countf.sh" that will count how many files or directories recursively. beside the file counts, also report how many files for each types (directory or regular files). It will either take arguments for specific directories and no argument. If no argument, it will read the current working directory as the starting point. Please also provide -h option to print out how to use your countf.sh program % ./countf.sh % ./countf.sh file1...

  • Write a MATLAB script, which asks the user to input the angle xd (in deg) and...

    Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylor's equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number,...

  • Question 2 (d) Write equivalent code to the one shown below by replacing the while loop...

    Question 2 (d) Write equivalent code to the one shown below by replacing the while loop with a for loop while x <= 15 x=x+1; end [4 marks] (e) Write the small program from the previous question using a single line of code with vector operations. [2 marks] (f) Write a MATLAB script that uses a loop to print the contents of two vectors interleaved in to one vector. Assume both vectors are the same length. For example, if A...

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
ADVERTISEMENT