Write a shell program to test whether a given number is even
or odd?
Answers were Sorted based on User's Feedback
Answer / fariha
echo -n "Enter numnber : "
read n
rem=$(( $n % 2 ))
if [ $rem -eq 0 ]
then
echo "$n is even number"
else
echo "$n is odd number"
fi
Is This Answer Correct ? | 240 Yes | 73 No |
Answer / mani
echo "Enter the Number"
read a
b=`echo "$a % 2"|bc`
if [ $b -eq 0 ]
then
echo "Given Number is Even "
exit
fi
echo " Given Number is odd"
Is This Answer Correct ? | 67 Yes | 34 No |
Answer / kushal
echo 10|awk '{ if($0 % 2 == 0) print "Even Number"; else
print"Odd Number"}'
tested and certified one liner answer
Is This Answer Correct ? | 28 Yes | 17 No |
Answer / rk
echo"enter number"
read n
set r=($n%2)
if(r eq-0)
then
echo "even number:$n"
else
echo "odd number:$n"
fi
Is This Answer Correct ? | 24 Yes | 16 No |
Answer / santana20142003
$ echo <number> | nawk '{ if($0 % 2 ==0) print $0 "Even
Number" ;\
else print $0 "Odd Number"}'
Is This Answer Correct ? | 24 Yes | 17 No |
Answer / karishma
echo -n "Enter numnber : "
set number = $<
set rem=expr( $number % 2 )
if($rem -eq 0)
then
echo "$number is even number"
else
echo "$number is odd number"
endif
Is This Answer Correct ? | 19 Yes | 19 No |
Answer / padmas
echo -n "Please give any odd number : "
read n
rem=$(( $n % 2 ))
if [ $rem -eq 0 ]
then
echo "Thank you for giving even number."
else
echo "Yes, it is odd"
fi
Is This Answer Correct ? | 9 Yes | 12 No |
What command needs to be used to take the backup?
Which is better perl or shell scripting?
What does sh mean?
Why are shell scripts used?
When you login to a c shell, which script would be run first?
Dear All, Can anybody tell me how to predefind no. of selected rows from a text file.
How will you print the login names of all users on a system?
What is shell terminal?
How can you find out how long the system has been running?
What is the best shell scripting language?
Explain about the exit command?
give me some website where i can get unix and testing meterials