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

Assignment-II

Write your name, roll number, PC number and assignment number in the
header of the program file as comments. You may give your program file name
as <asgn><no_><RollNo>.c. For example, a student with roll number
21CS1001 should name the program file for assignment number 2(a), as
asgn2a_21CS1001.c.

Submit all the programs separately against each assignment (i.e. asgn2a,
asgn2b, and asgn2c) in the Moodle System.

All the results for each assignment should be submitted together in a separate
file (named result.txt). Provide the result in a separate output file (named,
result_<assgn><no>.txt). Use standard output redirection feature to generate
the output file.

Hints. Suppose you would like to redirect your output to a file ‘result.txt’.
If you run the program with the following command

./a.out >result.txt

Output of your program (generated by printf(.) function) will be written


in file result.txt. You need to provide input from your input, by
remembering the sequence of inputs to be given.

If you execute the program multiple times, you may concatenate the
outputs in a single file by using the following redirection command:

./a.out >>result.txt

Input redirection (optional):

You may also store your input (the ordering as per requirement of
the program should be preserved) in an input file in.txt, and execute the
program as follows:

./a.out <in.txt >result.txt


2(a) Write a C-program which evaluates the value of the following
function as given below for an input real number x (to be read):

f(x)= x4-36x3+4x-3

The program also computes the sign of the derivative of the


function (f’(x)). If the derivative is positive, it prints ‘1’. If it is
negative, prints ‘-1’. Otherwise, it prints ‘0’. Run your program to
provide results for the following input numbers.

-5.4, 2.4, 3.0, 5.0, and 38.

2(b) Write a C-program which takes three distinct points (in 2-D
coordinates) as inputs and checks whether they form a triangle or
straight line. If they form a triangle, it prints “Formed triangle” and
prints its area. If they form a straight line, it prints “Formed Straight
Line” and prints the length between two end points. If any pair of
points are non-distinct, it prints coordinates of that point, and notifies
“Non-distinct input point” and prints the length between two distinct
points, if any.

Provide results for the following coordinate points:

(2,3), (4,5), (10,23)


(1,2), (4,8), (9,18)
(0,0), (1,3), (1,3)

2(c). Write a C-program and implement the function given in the


following diagram.
Provide functional values at the following values of x

x= 5, 15, 25, 40, and 60.

N.B. All your programs may be tested by other input values.

You might also like