Vous êtes sur la page 1sur 4

// 1.

Even or odd echo -n "Enter a number : " read n if [ `expr $n % 2` -eq 0 ] then echo "$n is Even" else echo "$n is Odd" fi

// Biggest of 3 numbers echo -n "Enter three numbers : " read a b c if [ $a -gt $b ] then if [ $a -gt $c ] then echo "Biggest else echo "Biggest fi else if [ $b -gt $c ] then echo "Biggest else echo "Biggest fi fi

is $a" is $c"

// 2. Positive negetive or zero echo -n "enter a number : " read a if [ $a -lt 0 ] then echo " $a is negetive" elif [ $a -gt 0 ] then echo "$a is Positive" else echo "$a is Zero" fi

is $b" is $c"

// 4. Number word echo -n "Enter the number less than 10 : " read n case $n in 1) echo 2) echo 3) echo 4) echo 5) echo 6) echo 7) echo 8) echo 9) echo 0) echo *) echo esac echo -n "Enter the numbers : " read a b case $n in 1) echo "Sum of $a and $b is `expr $a + $b`";; 2) echo "Difference of $a and $b is `expr $a $b`";; 3) echo "Product of $a and $b is `expr $a \* $b`";; 4) echo "Division of $a by $b is `expr $a / $b`";; *) echo "Invalid choice";; esac

"$n - ONE";; "$n - TWO";; "$n - THREE";; "$n - FOUR";; "$n - FIVE";; "$n - S IX";; "$n - SEVEN";; "$n - EIGHT";; "$n - NINE";; "$n - ZERO";; "Invalid choice";;

// 6. Sum of n numbers echo -n "Enter a number : " read n i=1 sum=0

//5. Calculator echo echo echo echo echo "Menu" "1 - Addition" "2 - Subtraction" "3 - Multiplication" "4 - Division" while [ $i -le $n ] do sum=`expr $i + $sum` i=`expr $i + 1` done echo "Sum is : $sum " echo -n "Enter your choice : " read n 2

// 7. Squares cubes echo -n "Enter a number : " read n echo -e "\t Number \t Square \t Cube" i=1 while [ $i -le $n ] do sq=`expr $i \* $i` cu=`expr $i \* $sq` echo -e "\t $i \t\t $sq \t\t $cu " i=`expr $i + 1` done

// 9. Reverse a number echo -n "Enter a number : " read n ori=$n i=0 while [ $n -gt 10 ] do mod=`expr $n % 10` i=`expr $i \* 10 + $mod` n=`expr $n / 10` done i=`expr $i \* 10 + $n` echo "Entered Number : $ori" echo "Reversed Number : $i"

// 8. Number of digits echo -n "Enter a number : " read n i=1 while [ $n -gt 10 ] do n=`expr $n / 10` i=`expr $i + 1` done echo Number of digits is $i 3

// 10. Read and display array. Find biggest and smallest in array echo "Enter 5 values : " for i in 0 1 2 3 4 do read a[$i] done echo "Entered values are " for (( i=0; i<5; i++)) do echo -e "\t ${a[$i]}" done big=${a[0]} small=${a[0]} for ((i=1;i<5;i++)) do if [ $big -lt ${a[i]} ] then big=${a[$i]} fi if [ $small -gt ${a[$i]} ] then small=${a[$i]} fi done echo "Biggest is $big" echo "Smallest is $small"

// 11. Sort 5 numbers echo "Enter 5 values : " for i in 0 1 2 3 4 do read a[$i] done echo "Entered Values are " for (( i=0; i<5; i++)) do echo -e "\t ${a[$i]}" done for ((i=0;i<4;i++)) do for ((j=`expr $i + 1`; j<5;j++)) do if [ ${a[$j]} -lt ${a[i]} ] then t=${a[$i]} a[$i]=${a[$j]} a[$j]=$t fi done done echo "Sorted Numbers : " for ((i=0;i<5;i++)) do echo -e "\t ${a[$i]}" done 4

Vous aimerez peut-être aussi