Unix Assignment

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

502 - UNIX and Shell Programming

Assignment - 1

Q1.) Create a script to check whether two numbers are equal or not.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q2.)Create a shell script to accept two numbers and find the greater
number.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q3.) Create a shell script to accept name and age and check whether
they are eligible for voting or not.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q4.) Create a script that accept a number and print positive if it is a


greater than zero and negative if it is less than zero.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q5.) Accept an integer as input and print the time of the day.

The input will be a single line containing an integer.

The output should be one of the these strings:

NIGHT,MORNING,AFTERNOON,EVENING,

INVALID.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q6.)You have some gold coins with you. You wish to divide this
among three of your

friends under the following conditions:

(1) All three of them should get a non-zero share.

(2) No two of them should get the same number of coins.

(3) You should not have any coins with you at the end of this sharing
process. The input has four lines. The first line contains the number of
coins with you. The next three lines will have the share given to your
three friends. If the division satisfies these conditions, then print FAIR.
If not, print UNFAIR.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q7.) Take three integer numbers as input. Check whether the given
numbers make

three sides of a triangle or not. [Hint 1: check whether they satisfy the
pythagorean

theorem (a2 + b2 = c2)

[Hint2: The greatest number of the three will be c2 ]

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q8.) Accept a point in an x-y graph as input and find the place that
this point belongs to.

A point could be in of the four quadrants, or it could be on the x-axis


or the y-axis, or it

could be the origin.

The input has 2 lines: the first line is the x-coordinate while the
second line is the

y-coordinate. The possible outputs are first, second, third, fourth, x-


axis, y-axis,

and origin. Any other output will be invalid.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q9.) Write a shell script that accepts a positive integer n as input and
prints the first n

positive integers.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q10.) Accept a positive integer n as input and print all the factors of n.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q11.) Accept a positive integer n as input, where n > 1 . Print PRIME if


n is a prime number and NOT PRIME otherwise.

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }


502 - UNIX and Shell Programming
Assignment - 1

Q12.) Accept a positive integer n as input and print the sum of all
prime numbers in the range [1,print 0.]

Answer:

Submitted By : 45 – Harsh J Mendapara (TYBCA) Page { PAGE \* MERGEFORMAT }

You might also like