$24
Total Score: 12 points
1 Assignment
1. Write a program that reads a char as input, and determines if it is a lowercase letter, uppercase letter, a digit or something else (call this a special character).
2. The Taylor series expansion for the exponential function, for small values of x is given by:
2
ex = 1 + x + x
x3
+ + . . .
2! 3!
Write a program that takes as input the value of x (for example 0.01), and computes ex using the above approximation. The program should sum up n terms, and stop when the value of the nth term is less than a predefined constant accuracy, set to 0.00001.
3. Write a program to generate m random integers from an array of size n, such that the probability of selecting even elements is twice that of odd elements. The same element may be selected multiple times. As an example, let n = 100 and m = 30. Read in the array elements from the provided data file ArrayInp.dat, using the fscanf() function. Utilize the function rand() to generate a pseudo random number and the function srand() to seed the random number generator. Start with the code RandomArrayGenerate.c provided on the Blackboard. An example on generating random numbers in a given range can be found at the link http : //www.cplusplus.com/ref erence/cstdlib/rand/.
4. Design an algorithm, and write the code to find all pairs of integers in a sorted array, which sum up to a specified value. For example, if the given array is
int arrN[10] = {1, 3, 7, 14, 22, 35, 44, 45, 46, 53};
and the specified sum is 49, the output would be:
3 46
14 35
The algorithm should work well for very large array sizes.
5. Write a program that initializes an array, and prints out its elements using the pointer notation
and pointer incrementing.
6. In the file Cauchy.dat provided on the Blackboard, find all occurrences of the word mathematician.
For reading the data from the input file, you can use the fscanf() function with the %s
specifier. Utilize the string function strcmp() for string comparison.
2 Grading
In addition to code functionality, there will be points for optimized algorithm, coding style and comments. A few useful comments would be sufficient.
3 Assignment Submission
The Assignments must be submitted on the Blackboard, and should include the following:
1. All the C code, that is, source in .c format, for the programming problems.
2. A screen shot showing your program executing.
3. A file (can be hand written, maybe in .PDF or .JPG format), if necessary, for the other problems.