


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Summer 2009 Name__________________ Date_____________________
1. Read the following program, and write the corresponding outputs when values of nSerial are 1, 3, 5, 7, and 9 respectively. (25 pts) #!/bin/sh
echo -n "Which fibonacci number do you want to see? "
read nSerial
a= b= count=2 # Used to control the number of iteration of the while loop fibonacci_number=$a
while [ $count -le $nSerial ]; do # Checks whether count is less than or equal to nSerial fibonacci_number=$[$a+$b] a=$b b=$fibonacci_number count=$[$count + 1] done
echo "Fibonacci $nSerial = $fibonacci_number"
2. Read the following program, describe the function of the program, and write the values of num for each step and the final output if we have the input of 5 34 8 20 15. (25 pts) #!/bin/bash echo "Input numbers --" read -a num numlen=${#num[*]} x=$numlen temp=
while [ $x -gt 0 ]; do i= while [ $i -lt $[$numlen-1] ]; do j=$[$i+1] # If the previous element in the array is greater than the next then swap the values. if [ ${num[i]} -gt ${num[j]} ] then temp=${num[i]} num[i]=${num[j]} num[j]=$temp fi i=$j done x=$[$x-1] done echo “The new sequence is: ${num[*]} “ 1. Sort the inputted numbers in ascending order 2. Iteration 1: 5 8 20 15 34 Iteration 2: 5 8 15 20 34 Iteration 3, 4, 5: 5 8 15 20 34 3. The final output
4. Programming problem. Write a script to find the maximum, minimum, and the average of n numbers from the command line in Bourne Shell. (25 pts) [fgu@qubit ~]$./file 8 16 12 4 The maximum of 8 16 12 4 is: 16 The minimum of 8 16 12 4 is: 4 The average of 8 16 12 4 is: 10