Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://pastebin.com/GVkLgAMH
- 1.Even odd
- clear
- echo "Enter the number"
- read num
- if ((num % 2==0))
- then
- echo "$num is even"
- else
- echo "$num is odd"
- fi
- 2.Factorial number
- clear
- fec=1
- echo "Enter an interger number"
- read num
- if (( num < 0 ))
- then echo "Negative value is not allow"
- else
- for (( i=1; i<=num; ++i ))
- do
- fec=$(( fec * i ))
- done
- echo "$fec"
- fi
- 3.fibonacci number
- clear
- echo -n "Enter a Number :"
- read num
- a=0
- b=1
- echo "The Fibonacci sequence for the number $num is : "
- for (( i=0;i<=num;i++ ))
- do
- echo "$a "
- next=$((a+b))
- a=$b
- b=$nextdone
- 4.GPA calculator
- clear
- echo "Enter the
- read num
- number"
- if (( num >=80 ))
- then echo "the result is A+"
- elif ((num >= 70))
- then echo "the result is A"
- elif ((num >= 60))
- then echo "the result is A-"
- elif ((num >= 50))
- then echo "the result is B+"
- else
- echo "you and your exam
- went to hell"
- fi
- 5.find the lowest number
- clear
- echo "Enter the 1st number"
- read num1
- echo "Enter the 2nd number"
- read num2
- echo "Enter the 3rd number"
- read num3
- if (( $num1 < $num2 ))
- then if(( $num1 < $num3 ))
- then echo "$num1 is lowest"
- else echo "$num3 is lowest"
- fi
- elif (($num2 < $num1 ))
- then if (($num2 <$num3 ))
- then echo "$num2 is lowest"else echo "$num3 is lowest"
- fi
- fi
- 6.prime number check
- clear
- flag=0
- echo "Enter the number"
- read num
- m=$(( num / 2 ))
- for ((i=2; i<= $m; i++ ))
- do
- if(( $num % i ==0 ))
- then echo "$num is not prime "
- flag=1
- exit 0
- fi
- done
- if(( $flag == 0))
- then echo "$num is prime"
- fi
- 7.Palindrome
- num=545
- # Storing the remainder
- s=0
- # Store number in reverse
- # order
- rev=""
- # Store original number
- # in another variable
- temp=$num
- while [ $num -gt 0 ]
- do
- # Get Remainder
- s=$(( $num % 10 ))
- # Get next digit
- num=$(( $num / 10 ))
- # Store previous number and
- # current digit in reverse
- rev=$( echo ${rev}${s} )
- done
- if [ $temp -eq $rev ];
- then
- echo "Number is palindrome"
- else
- echo "Number is NOT palindrome"
- fi
- 8. Fibonacci
- # Program for Fibonacci
- # Series
- # Static input fo N
- N=6
- # First Number of the
- # Fibonacci Series
- a=0
- # Second Number of the
- # Fibonacci Series
- b=1
- echo "The Fibonacci series is : "
- for (( i=0; i<N; i++ ))
- do
- echo -n "$a "
- fn=$((a + b))
- a=$b
- b=$fn
- done
- # End of for loop
- 9.Prime or not
- #storing the number to be checked
- number=43
- i=2
- #flag variable
- f=0
- #running a loop from 2 to number/2
- while test $i -le `expr $number / 2`
- do
- #checking if i is factor of number
- if test `expr $number % $i` -eq 0
- then
- f=1
- fi
- #increament the loop variable
- i=`expr $i + 1`
- done
- if test $f -eq 1
- then
- echo "Not Prime"
- else
- echo "Prime"
- fi
- 10.Average of given numbers in Bash
- # Total numbers
- n=5
- # copying the value of n
- m=$n
- # initialized sum by 0
- sum=0
- # array initialized with
- # some numbers
- array=(1 2 3 4 5)
- # loop until n is greater
- # than 0
- while [ $n -gt 0 ]
- do
- # copy element in a
- # temp variable
- num=${array[`expr $n - 1`]}
- # add them to sum
- sum=`expr $sum + $num`
- # decrement count of n
- n=`expr $n - 1`
- done
- # displaying the average
- # by piping with bc command
- # bc is bash calculator
- # command
- avg=`echo "$sum / $m" | bc -l`
- printf '%0.3f' "$avg"
- 11.Bash shell script to find sum of digits
- # !/bin/bash
- # Program to find sum
- # of digits
- # Static input of the
- # number
- Num=123
- g=$Num
- # store the sum of
- # digits
- s=0
- # use while loop to
- # caclulate the sum
- # of all digits
- while [ $Num -gt 0 ]
- do
- # get Remainder
- k=$(( $Num % 10 ))
- # get next digit
- Num=$(( $Num / 10 ))
- # calculate sum of
- # digit
- s=$(( $s + $k ))
- done
- echo "sum of digits of $g is : $s"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement