You are on page 1of 7

Program 1 WAP to concatenate the contents of 2 files ?

cat > first hai this is first file ^d cat > second hai this is Second file ^d program ------vi prog1 echo contents of first file cat first echo contents of second file cat second echo contents of third file cat first second > third cat third esc : x

output -----sh prog1 Program 2 WAP to Find SUm,AVG,PRODUCT of 4 numbers ? vi prog2 clear echo enter A,B,C,D values read read read read a b c d

sum= `Expr $a + $b + $c + $d` Avg= `Expr $sum /4` Product= `Expr $a \* $b \* $c \*d`

echo Sum is $sum echo Avg is $Avg echo Product is $ Product esc:x output -----sh prog2 Program 3 WAP to change two values with out using another variable ? vi prog3 clear echo enter A,B values read a read b echo actual values are A="$a" and B="$b" a=`Expr $a + $b` b=`Expr $a - $b` a=`Expr $a - $b` echo swapped values are "A"=$a and "B"=$b esc:x output ----sh prog3 Program 4 WAP to find largest of 3 numbers vi prog4 clear read a read b read c if [$a -eq $b -a $b -eq $c then echo 3 numbers are equal

elif [$a -gt $b -a $a -gt $c] then echo $a is Bigger elif [$b -gt $c] then echo $b is Bigger else echo $c is Bigger fi output -----sh prog4 Program 5 WAp to find the Factorial of a given number vi prog5 clear echo enter the number to get Factorial read n fact=1 i=$n while [$n -ge 1] do fact =`Expr $fact \* $n` n=`Expr $n-1` done echo Factorial of $i is $fact output -----sh prog5 Program 6 WAP to find the Sum of INDIVIDUAL digits of given numbers vi prog6 clear echo enter any number having atleast 2 digits read n i=$n

r=0 sum=0 while test $n -gt 0 do r=`Expr $n %10` sum=`Expr $sum + $r` n=`Expr $n/10` done echo sum of individual digits of $i is $sum output ------sh prog6 Program 7 WAP to find the reverse of a given number vi prog7 clear echo enter a number read n m=$n x=0 while test $n -gt 0 do r=`Expr $n %10` x=`Expr $x \*10 + $r` n=`Expr $n/10` done echo reverse of given number is $x output -----sh prog7 Program 8 WAP to generate fibnacci series vi prog8 clear echo enter any number read n

fo=0 f1=1 echo $fo echo $f1 i=2 while test $i le $n do f2=`Expr $fo + $f1` echo $f2 f0=$f1 f1=$f2 i=`Expr $i+1` done output -----sh prog8 Program 9 WAP to check whether a given number is PALLENDROME or NOT vi prog9 echo enter any number read n x=0 m=$n while test $n -gt 0 do r=`Expr $n%10` x=`Expr $x \*10 +r` n=`Expr $n/10` done if test $x -eq $m then echo given number is PALLENDROME else echo given number is NOT a PALLENDROME fi output -----sh prog9

Program 10 Write a menu Driven Prog vi prog10 clear echo "1.Contents of a FILE " echo echo "2.Present Working Directory" echo echo "3.EXIT" echo echo "Enter your Choice" read ch case $ch in 1)echo enter file name read filename cat $filename ;; 2)echo present working directory pwd ;; 3)echo program EXIT ;; *)echo Incorrect choice ;; esac output ------sh prog10 Program 11 WAP to count the no.of UPPER case letters , no.of lowercase letters, no.of digits and no.of DIGITS and no.of Special characters in a given string vi prog11 clear echo enter a string read s len=`echo $s |wc-c` h=`echo $len -1` echo length is $h u=0

l=0 d=0 sc=0 while test $n -gt 0 do a=`echo $s |cat-c $n` case $a in [a-z]) l=`Expr $l+1` ;; [A-Z]) u=`Expr $u+1` ;; [0-9]) d=`Expr $d+1` ;; *) sc=`Expr $sc+1` ;; esac n=`Expr $n-1` done echo echo echo echo no.of no.of no.of no.of uppercase letters are $u lowercase letters are $l digits are $d special characters are $sc

You might also like