Advertisement
AyAks69

skp lab

Jan 31st, 2023 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.49 KB | Source Code | 0 0
  1. q1
  2. #!/bin/bash
  3.  
  4. echo "Enter the coefficients of the quadratic equation (a, b, c): "
  5. read a b c
  6.  
  7. # calculate the discriminant
  8. d=$(echo "scale=2; ($b*$b) - (4*$a*$c)" | bc)
  9.  
  10. # calculate the roots
  11. if (( $(echo "$d > 0" | bc -l) )); then
  12.   root1=$(echo "scale=2; (-$b + sqrt($d)) / (2 * $a)" | bc)
  13.   root2=$(echo "scale=2; (-$b - sqrt($d)) / (2 * $a)" | bc)
  14.   echo "Roots are: $root1 and $root2"
  15. elif (( $(echo "$d == 0" | bc -l) )); then
  16.   root1=$(echo "scale=2; -$b / (2 * $a)" | bc)
  17.   echo "Root is: $root1"
  18. else
  19.   echo "Roots are complex numbers."
  20. fi
  21.  
  22.  
  23. q2
  24. #!/bin/bash
  25. read -p "Enter a number" n
  26. rev=0
  27. alt=$n
  28. while [ $alt -gt 0 ]
  29. do
  30.     temp=$(( alt%10 ))
  31.     rev=$(( $rev*10+$temp ))
  32.     alt=$(( alt/10 ))
  33. done
  34. if [ $rev -eq $n ]
  35. then
  36.     echo "$n is a palindrome number"
  37. else
  38.     echo "$n is not a palindrom number"
  39. fi
  40.  
  41. q3
  42. #!/bin/bash
  43. read -p "Enter name " name
  44. read -p "Enter rol number " roll_no
  45. read -p "Enter marks " marks
  46. echo -e "Student report\n Name: $name\n Roll Number: $roll_no\n Marks:$marks"
  47.  
  48. q4
  49. #!/bin/bash
  50. read -p "Enter the radius of the circle in mm " r
  51. area=$(echo "scale=3;(3.14*$r*$r)" | bc)
  52. circum=$(echo "scale=3;(2*3.14*$r)" | bc)
  53. echo -e  "Radius is $r\nCircumference is $circum mm\nArea is $area mm^2"
  54.  
  55. q5
  56. #!/bin/bash
  57. read -p "Enter a string " s
  58. rev=""
  59. l=${#s}
  60. while [ $l -gt 0 ]
  61. do
  62.     add=${s:(l-1):1}
  63.     rev="${rev}${add}"
  64.     l=$(( l-1 ))
  65. done
  66. if [ $s = $rev ]
  67. then
  68.     echo "$s is a palindrome string"
  69. else
  70.     echo "$s is not a palindrome string"
  71. fi
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement