Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- q1
- #!/bin/bash
- echo "Enter the coefficients of the quadratic equation (a, b, c): "
- read a b c
- # calculate the discriminant
- d=$(echo "scale=2; ($b*$b) - (4*$a*$c)" | bc)
- # calculate the roots
- if (( $(echo "$d > 0" | bc -l) )); then
- root1=$(echo "scale=2; (-$b + sqrt($d)) / (2 * $a)" | bc)
- root2=$(echo "scale=2; (-$b - sqrt($d)) / (2 * $a)" | bc)
- echo "Roots are: $root1 and $root2"
- elif (( $(echo "$d == 0" | bc -l) )); then
- root1=$(echo "scale=2; -$b / (2 * $a)" | bc)
- echo "Root is: $root1"
- else
- echo "Roots are complex numbers."
- fi
- q2
- #!/bin/bash
- read -p "Enter a number" n
- rev=0
- alt=$n
- while [ $alt -gt 0 ]
- do
- temp=$(( alt%10 ))
- rev=$(( $rev*10+$temp ))
- alt=$(( alt/10 ))
- done
- if [ $rev -eq $n ]
- then
- echo "$n is a palindrome number"
- else
- echo "$n is not a palindrom number"
- fi
- q3
- #!/bin/bash
- read -p "Enter name " name
- read -p "Enter rol number " roll_no
- read -p "Enter marks " marks
- echo -e "Student report\n Name: $name\n Roll Number: $roll_no\n Marks:$marks"
- q4
- #!/bin/bash
- read -p "Enter the radius of the circle in mm " r
- area=$(echo "scale=3;(3.14*$r*$r)" | bc)
- circum=$(echo "scale=3;(2*3.14*$r)" | bc)
- echo -e "Radius is $r\nCircumference is $circum mm\nArea is $area mm^2"
- q5
- #!/bin/bash
- read -p "Enter a string " s
- rev=""
- l=${#s}
- while [ $l -gt 0 ]
- do
- add=${s:(l-1):1}
- rev="${rev}${add}"
- l=$(( l-1 ))
- done
- if [ $s = $rev ]
- then
- echo "$s is a palindrome string"
- else
- echo "$s is not a palindrome string"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement