You are on page 1of 2

# Program to print the

# given pattern

# Static input for N


N=6

# variable used for


# while loop
i=0
j=0

while [ $i -le `expr $N - 1` ]


do
j=0

while [ $j -le `expr $N - 1` ]


do
if [ `expr $N - 1` -le `expr $i + $j` ]
then
# Print the pattern
echo -ne "* "
else
# Print the spaces required
echo -ne " "
fi
j=`expr $j + 1`
done
# For next line
echo

i=`expr $i + 1`
done

#!/bin/bash
echo -e "Enter Number : \c"
read n
for((i=2; i<=$n/2; i++))
do
ans=$(( n%i ))
if [ $ans -eq 0 ]
then
echo "$n is not a prime number."
exit 0
fi
done
echo "$n is a prime number."

echo Enter number:


read n
num=0
on=$n
while [ $n -gt 0 ]
do
num=$(expr $num \* 10)
k=$(expr $n % 10)
num=$(expr $num + $k)
n=$(expr $n / 10)
done
if [ $num -eq $on ]
then
echo
echo $on is a palindrome
else
echo
echo $on is not a palindrome
fi

# Program for Fibonacci


# Series

# Static input for N


echo Enter num:
read N

# 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

#shell script for factorial of a number


#factorial using while loop

echo "Enter a number"


read num

temp=$num
fact=1

while [ $num -gt 1 ]


do
fact=$((fact * num)) #fact = fact * num
num=$((num - 1)) #num = num - 1
done

echo Factorial of $temp is $fact

You might also like