

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Main points of this past exam are: Program, Simply Typing, Compile, Text Editor, Functionality, Designed, Lines of Code
Typology: Exams
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Programing part of Exam 1 will consist of one problem for which you will be asked to write a program in C. You can use your favorite text editor, such as vi or nano. You should name your source code file exam1.c. You can compile your code using gcc compiler as follows:
gcc -g -Wall -Werror -ansi exam1.c -o test
You can then run your program by simply typing
./test
Make sure your program compiles and works before your turn it in. We will not grade a program that does not compile and you will lose points if the program compiles with warnings. You obviously will not receive any points if your program does not do what it is supposed to do. Both functionality and coding style will be graded, with most points given for functionality and some points given for style. No style grading will be done if the program does not compile.
The programming part of the exam is designed to be one hour long. Not including comments and empty lines, the exam program can be written in less than 20 lines of code. If your program grows in size to over 30 lines, you are probably doing something wrong.
Instructions how to turn in your program will be provided at the exam.
In this problem, we will estimate cos( x ) function using Taylor series expansion:
where n is the degree of the Taylor series expansion and x is an angle in radians. The program should print a prompt "Enter x in radians: " and take x in radians as an input. Then the program should print a prompt "Enter the number of terms: " and take n as input. It then should approximate the value of cos( x ) using the first n terms of the Taylor series expansion and print out the value of cos(x). Assume the value of x is always given in the range of –π to +π.
You may find cos( x ) function plot useful for debugging purposes:
In this problem, we will write a program to compute integral of a function f ( x )= x^2 +2 x +3 on an interval [ a , b ] using Riemann sum method with left endpoint function evaluation rule:
∫ ∑ ( )
where n is the number of rectangles used in the approximation. The program should print "Enter a and b values: " and take integration interval boundaries a and b as inputs. Then the program should print "Enter the number of terms: " and take n as input. It then should approximate the value of integral for the user-specified interval [ a , b ] and number n using the above definition. Assume that input is always given such that a < b.
You may find y= x^2 +2 x +3 function plot useful for debugging purposes: