Write a shell program to test whether a given number is even
or odd?

Answers were Sorted based on User's Feedback



Write a shell program to test whether a given number is even or odd?..

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

Write a shell program to test whether a given number is even or odd?..

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

Write a shell program to test whether a given number is even or odd?..

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

Write a shell program to test whether a given number is even or odd?..

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

Write a shell program to test whether a given number is even or odd?..

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

Write a shell program to test whether a given number is even or odd?..

Answer / 111

1111

Is This Answer Correct ?    8 Yes 7 No

Write a shell program to test whether a given number is even or odd?..

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

Write a shell program to test whether a given number is even or odd?..

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

Post New Answer

More Shell Script Interview Questions

How will you schedule a job that will run every month last day?(some months have 30 days,some 31 days,28,29 days)

1 Answers   NTT Data, TCS,


Hello all, This is my assignment on shell scripting, can anyone help me regarding this ? Create a shell script which connects to the database In second shell script include the first script for the DB connection Create a table (PRADEEP_DATA) with 2 columns (name, value) In Third shell script include the first script for the DB connection And insert/delete the values from the Table, by accepting input from the user This functionality should be a menu driven Program: 1) Insert to the database a. Name b. value 2)Delete from the database a.Name b.value Exception handling needs to be taken care.

0 Answers   Cap Gemini, Wipro,


How to print all the arguments provided to the script?

0 Answers  


What happens on a system call?

0 Answers  


In a file , how to retrieve the lines which are the multiples of 50 ? like 50,100,150th lines etc.

9 Answers   Amazon,


Is cmd a shell?

0 Answers  


How to print some text on to the screen?

2 Answers  


Explain about echo command?

0 Answers  


How do I start a shell script?

0 Answers  


Give some situations where typing error can destroy a program?

0 Answers  


I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.

0 Answers  


Hi, i want to zip the files that generates automatically every few minutes (files generated are in .arc extension)....any body write a script for this... thanks in advance

5 Answers   HP,


Categories