Professional Documents
Culture Documents
Duration: 3 hours
Total Marks: 20
1. Tables [Contd]: Write another program by modifying your program in Lab 2 so that it also works for real numbers. However, while printing the real values, make sure that there are no more than 2 digits after decimal as shown below
$./a.out Enter the number: 0.25 0.25 x 1 = 0.25 0.25 x 2 = 0.50 0.25 x 3 = 0.75 0.25 x 4 = 1.00 0.35 x 5 = 1.25
[Total 6 marks] 2. Type Casting: Write a program that takes as input a double number (say 'x') and does the following (a) (b) (c) (d) Typecast it into an integer variable 'a' and print it. Typecast 'a' back into double and print it. Typecast it into an oat variable 'b' and print it. Typecast 'b' back into double and print it. (1 mark) (1 mark) (1 mark) (1 mark)
[Total 4 marks] 3. Functions: Dene two functions, mysin() and mycos(), to compute the sine and cosine of an angle (provided in degrees). Your program should rst ask the user to present a choice:
On an input "1", the program should read an integer (value of an angle in degrees) and should call the function mysin() to print the value of sine of that input using the following expansion:
(3marks) On the input "2", it should read an integer (value of an angle in degrees) and call a function mycos() to print the value of cosine of that input using the following expansion: (3 marks)
You can ignore the terms after the third term in the expansions. Also, see the dierence in your implementation using the inbuilt sin(x) and cos(x) functions in the math.h library. (2 marks)
Note: The argument to these library functions (in math.h) and the variable in the expansions is in radians. Use the following for the conversion:
angle in radian = (angle in degrees * (PI))/180 Use the value of PI to be 3.14159
(2 mark)
IMPORTANT: In this part of the lab assignment, use the following command to compile your code:
$gcc prog.c -lm
[Total 10 marks]