You are on page 1of 2

CS19003 Programming and Data Structures

Assignment 2

General instruction to be followed strictly

1. Do not use any global variable unless you are explicitly instructed so.

2. Use proper indentation in your code and comment.

3. Name your file as <roll_no>_a<asst_no>. For example, if your roll number is 14CS10001 and
you are submitting assignment 2, then name your file as 14CS10001_a2.c .

4. Write your name, roll number, and test number at the beginning of your program.

5. Make your program as efficient as possible.

1. Write a C program that evaluates the following arithmetic expressions and then prints out the
result:

B X = (1.234 × 105 ) + (7.5 × 10−3 )


B Z = 19.2 sin 25 + (5.6 + 12/7.2) × 105

2. Write a C program that:

B takes as input a value f which is a temperature in Fahrenheit,


B converts f to the value c in Centigrade,
B rounds off the floating point number c to its nearest integer a. E.g, 41.5C will become 42C,
41.1C becomes 41C and 41.6C becomes 42C.
B prints “The temperature in Centigrade, rounded to the nearest integer is = a.”

3. Write C program which:

B reads a floating point number x and an integer n from the keyboard,


B computes S = x + (x + 1) + (x + 2) + (x + 3) + . . . + (x + n),
B prints S.

4. Write a C program that:

B takes as input three pairs of integer coordinates p1 = (x1 , y1 ), p2 = (x2 , y2 ), p3 = (x3 , y3 ) from
the keyboard,
B calculates the area A and perimeter B of the triangle formed by the 3 input points p1 , p2 , p3
of the 2D-plane,
B prints A and B.

You may need to use math library function: #include < math.h >
If you want to compile using the terminal then use the command
gcc ./program.c -lm
Proper commenting, indentation and output commands carry marks.

1
Policy on Plagiarism
Academic integrity is expected of all the students. Ideally, you should work on the assignment/exam
consulting only the material we share with you. You are required to properly mention/cite anything else
you look at. Any student submitting plagiarised code will be penalised heavily. Repeated violators of our
policy will be deregistered from the course. Read this to know what is plagiarism.

You might also like