Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
0 of .
Results for:
P. 1
Write a Shell Program to Find the Largest Among Three Numbers

# Write a Shell Program to Find the Largest Among Three Numbers

Ratings: (0)|Views: 394 |Likes:

### Availability:

See more
See less

05/20/2014

pdf

text

original

Write a Shell program to find the largest among three numbers.PROGRAM

echo "Enter the first number:"read aecho "Enter thesecond number:"read becho "Enter the third number:"readcif [ \$a -gt \$b -a \$a -gt \$c ]thenecho "\$s isgreater"elif [ \$b -gt \$c ]thenecho "\$b isgreater"elseecho "\$c is greater"fi

OUTPUT

-bash-3.2\$ sh larthree.shEnter the first number:20Enterthe second number:30Enter the third number:1030 isgreater-bash-3.2\$
26. Write a Shell program to find the largest among
‘n’ different
numbers.PROGRAM

echo "Enter the number of elements:"read nl=0for((i = 1; i <= n ; i++))doecho "Enter the number:"read noif [\$no -gt \$l ]thenl=\$nofidoneecho "The largest numbers is: \$l"

OUTPUT

-bash-3.2\$ sh largest.shEnter the number ofelements:5Enter the number:44Enter the number:55Enterthe number:33Enter the number:22Enter the number:11Thelargest numbers is : 55
27. Write a Shell program to find the largest digit of a number.PROGRAM

echo "Enter a number:"read ns=0while [ \$n -gt 0]dor=`expr \$n % 10`if [ \$r -gt \$s ]thens=\$rfin=`expr \$n/ 10`doneecho "The largest digit is : \$s"

OUTPUT

-bash-3.2\$ sh large.shEnter a number:143The largestdigit is : 4-bash-3.2\$ sh large.shEnter a number:786Thelargest digit is : 8

Write a Shell program to find
the sum of ‘n’ different numbers.PROGRAM

echo "Enter the number of elements:"read ns=0for((i = 1; i <= n ; i++))doecho "Enter the number:"readnos=`expr \$s + \$no`doneecho "The sum is : \$s"

OUTPUT

-bash-3.2\$ sh sum.shEnter the number of elements:5Enterthe number:11Enter the number:22Enter thenumber:33Enter the number:44Enter the number:55The sumis : 165
Write a Shell program to find the sum of digits of a number.PROGRAM

echo "Enter a number:"read ns=0while [ \$n -gt 0]dor=`expr \$n % 10`s=`expr \$s + \$r`n=`expr \$n /10`doneecho "The sum of digit is : \$s"

-bash-3.2\$ sh sumdigit.shEnter anumber:14The sum of digit is : 5-bash-3.2\$ shsumdigit.shEnter a number:1983The sum of digit is : 21
30. Write a Shell program to print the reverse of a number.PROGRAM

echo "Enter a number:"read nt=\$ns=0while [ \$n -gt 0]dor=`expr \$n % 10`s=`expr \$r + \$s \* 10`n=`expr \$n /10`doneecho "The reverse of the number \$t is \$s"

OUTPUT

-bash-3.2\$ sh revnum.shEnter anumber:123The reverse of the number 123 is 321
31. Write a Shell program to find the factorial of a number using forloop.PROGRAM

echo "Enter a number:"read nf=1for((i = 1 ; i <= n ;i++))dof=`expr \$f \* \$i`doneecho "The factorial of \$nis \$f"