odd even etc

 

 

 

EX.NO:3.hODD OR EVEN NUMBERS

Aim:

To Write a shell Program on whether a given number odd or even.

 

Algorithm:

Step1: Declare the  variable A.

Step2: Assign value to the variable

Step3Perform A modulo 2 and check result if output is 0

Step4: If true print A is even

Step5: If false print A is odd

 

 

Program Code:   

.

.

.

0

 

 

Sample I/P:

enter the no

5

Sample O/P:

5 is odd

 

 

 

RESULT:Thus the program was executed and verified successfully.

 

VIVA-VOCE QUESTIONS:

1. How do you determine odd and even?

 

 

 

 

 

 

 

 

 

 

 

EX.NO:3.iLEAP YEAR

Aim:

To Write a shell Program on whether a given number leap year or not.

 

Algorithm:

Step1: Declare the variable A.

Step2: Assign value to the variable

Step3: Check if year is divisible by 4 but not 100, DISPLAY "leap year"

Step4: Check if year is divisible by 400, DISPLAY "leap year"

Step5: Otherwise, DISPLAY "not leap year"

 

 

 

Program Code:   

clear

echo “enter year"

read a

x=`expr $a % 100`

y=`expr $a % 400`

z=`expr $a % 4`

if [ $x -eq 0 ]

then

if [ $y -eq 0 ]

then

echo "leap year"

else

echo " Not a leap year"

fi

else

if [ $z -eq 0 ]

then

echo "leap year"

else

echo " Not a leap year"

fi

fi

 

 

Sample I/P1:

enter year

2012

Sample O/P:

leap year

Sample I/P 2:

                 enter year

Sample O/P:

                  2015

                  Not a leap year

 

 

RESULT:Thus the program was executed and verified successfully.

 

 

VIVA-VOCE QUESTIONS:

1. Which operator can’t be used on float data?

2. Write syntax for if-statement

3. What are the restrictions on % operator?

 

 

 

EX.NO:3.jMARKS OBTAINED

Aim: write a shell program marks obtained by a student in Five different subjects input through keyword student get division as following tools i)60 division ii)50-59 division III)40-49    division

 

Algorithm:

Step1: Declare the  variable of five subject.

Step2: Assign value to the variable and calculate the total value and percentage.

Step3: Check if percentage is greater then equal to 60 then It’s1stdivision ,if percentage is greater then equal to 60 then It’s 2nd division and if percentage is greater then equal to 40 then  It’s 3rd division

Step4: Check if year is divisible by 400, DISPLAY "leap year"

Step5: Otherwise, DISPLAY "fail"

 

Program Code:   

clear

echo “Enter marks of five subject"

read a

read b

read c

read d

read e

total=`expr $a + $b + $c + $d + $e`

per=`expr $total / 5`

if [ $per -ge 60 ]

then

echo " 1st div"

elif [ $per -ge 50 ]

then

echo " 2nd div "

elif [ $per -ge 40 ]

then

echo " 3rd div"

else

echo " fail"

fi

 

Sample I/P:

Enter marks of five subject

80

73

65

60

65

Sample O/P:

             1st div

 

 

RESULT:Thus the program was executed and verified successfully

 

VIVA-VOCE QUESTIONS:

1. Which is use of read command?

2. Write syntax for else if-statement

 

 

 

 

 

Comments

Popular posts from this blog

what is Machenical Engineering

PHOTO ( CHINESE LADKA)

Arithmatic operations, factorial of a number, while loop, prime number, etc