Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. https://pastebin.com/GVkLgAMH
  2.  
  3. 1.Even odd
  4. clear
  5. echo "Enter the number"
  6. read num
  7. if ((num % 2==0))
  8. then
  9. echo "$num is even"
  10. else
  11. echo "$num is odd"
  12. fi
  13.  
  14.  
  15.  
  16. 2.Factorial number
  17. clear
  18. fec=1
  19. echo "Enter an interger number"
  20. read num
  21. if (( num < 0 ))
  22. then echo "Negative value is not allow"
  23. else
  24. for (( i=1; i<=num; ++i ))
  25. do
  26. fec=$(( fec * i ))
  27. done
  28. echo "$fec"
  29. fi
  30.  
  31.  
  32.  
  33. 3.fibonacci number
  34. clear
  35. echo -n "Enter a Number :"
  36. read num
  37. a=0
  38. b=1
  39. echo "The Fibonacci sequence for the number $num is : "
  40. for (( i=0;i<=num;i++ ))
  41. do
  42. echo "$a "
  43. next=$((a+b))
  44. a=$b
  45. b=$nextdone
  46.  
  47.  
  48.  
  49. 4.GPA calculator
  50. clear
  51. echo "Enter the
  52. read num
  53. number"
  54. if (( num >=80 ))
  55. then echo "the result is A+"
  56. elif ((num >= 70))
  57. then echo "the result is A"
  58. elif ((num >= 60))
  59. then echo "the result is A-"
  60. elif ((num >= 50))
  61. then echo "the result is B+"
  62. else
  63. echo "you and your exam
  64. went to hell"
  65. fi
  66.  
  67.  
  68.  
  69.  
  70. 5.find the lowest number
  71. clear
  72. echo "Enter the 1st number"
  73. read num1
  74. echo "Enter the 2nd number"
  75. read num2
  76. echo "Enter the 3rd number"
  77. read num3
  78. if (( $num1 < $num2 ))
  79. then if(( $num1 < $num3 ))
  80. then echo "$num1 is lowest"
  81. else echo "$num3 is lowest"
  82. fi
  83. elif (($num2 < $num1 ))
  84. then if (($num2 <$num3 ))
  85. then echo "$num2 is lowest"else echo "$num3 is lowest"
  86. fi
  87. fi
  88.  
  89.  
  90.  
  91. 6.prime number check
  92. clear
  93. flag=0
  94. echo "Enter the number"
  95. read num
  96. m=$(( num / 2 ))
  97. for ((i=2; i<= $m; i++ ))
  98. do
  99. if(( $num % i ==0 ))
  100. then echo "$num is not prime "
  101. flag=1
  102. exit 0
  103. fi
  104. done
  105. if(( $flag == 0))
  106. then echo "$num is prime"
  107. fi
  108.  
  109.  
  110. 7.Palindrome
  111. num=545
  112.  
  113. # Storing the remainder
  114. s=0
  115.  
  116. # Store number in reverse
  117. # order
  118. rev=""
  119.  
  120. # Store original number
  121. # in another variable
  122. temp=$num
  123.  
  124. while [ $num -gt 0 ]
  125. do
  126. # Get Remainder
  127. s=$(( $num % 10 ))
  128.  
  129. # Get next digit
  130. num=$(( $num / 10 ))
  131.  
  132. # Store previous number and
  133. # current digit in reverse
  134. rev=$( echo ${rev}${s} )
  135. done
  136.  
  137. if [ $temp -eq $rev ];
  138. then
  139. echo "Number is palindrome"
  140. else
  141. echo "Number is NOT palindrome"
  142. fi
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151. 8. Fibonacci
  152. # Program for Fibonacci
  153. # Series
  154.  
  155. # Static input fo N
  156. N=6
  157.  
  158. # First Number of the
  159. # Fibonacci Series
  160. a=0
  161.  
  162. # Second Number of the
  163. # Fibonacci Series
  164. b=1
  165.  
  166. echo "The Fibonacci series is : "
  167.  
  168. for (( i=0; i<N; i++ ))
  169. do
  170. echo -n "$a "
  171. fn=$((a + b))
  172. a=$b
  173. b=$fn
  174. done
  175. # End of for loop
  176.  
  177.  
  178.  
  179.  
  180. 9.Prime or not
  181. #storing the number to be checked
  182. number=43
  183. i=2
  184.  
  185. #flag variable
  186. f=0
  187.  
  188. #running a loop from 2 to number/2
  189. while test $i -le `expr $number / 2`
  190. do
  191.  
  192. #checking if i is factor of number
  193. if test `expr $number % $i` -eq 0
  194. then
  195. f=1
  196. fi
  197.  
  198. #increament the loop variable
  199. i=`expr $i + 1`
  200. done
  201. if test $f -eq 1
  202. then
  203. echo "Not Prime"
  204. else
  205. echo "Prime"
  206. fi
  207.  
  208.  
  209.  
  210. 10.Average of given numbers in Bash
  211. # Total numbers
  212. n=5
  213.  
  214. # copying the value of n
  215. m=$n
  216.  
  217. # initialized sum by 0
  218. sum=0
  219.  
  220. # array initialized with
  221. # some numbers
  222. array=(1 2 3 4 5)
  223.  
  224. # loop until n is greater
  225. # than 0
  226. while [ $n -gt 0 ]
  227. do
  228. # copy element in a
  229. # temp variable
  230. num=${array[`expr $n - 1`]}
  231.  
  232. # add them to sum
  233. sum=`expr $sum + $num`
  234.  
  235. # decrement count of n
  236. n=`expr $n - 1`
  237. done
  238.  
  239. # displaying the average
  240. # by piping with bc command
  241. # bc is bash calculator
  242. # command
  243. avg=`echo "$sum / $m" | bc -l`
  244. printf '%0.3f' "$avg"
  245.  
  246.  
  247.  
  248.  
  249.  
  250. 11.Bash shell script to find sum of digits
  251. # !/bin/bash
  252.  
  253. # Program to find sum
  254. # of digits
  255.  
  256. # Static input of the
  257. # number
  258. Num=123
  259. g=$Num
  260.  
  261. # store the sum of
  262. # digits
  263. s=0
  264.  
  265. # use while loop to
  266. # caclulate the sum
  267. # of all digits
  268. while [ $Num -gt 0 ]
  269. do
  270. # get Remainder
  271. k=$(( $Num % 10 ))
  272.  
  273. # get next digit
  274. Num=$(( $Num / 10 ))
  275.  
  276. # calculate sum of
  277. # digit
  278. s=$(( $s + $k ))
  279. done
  280. echo "sum of digits of $g is : $s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement