## Physics 222/322 Assignment 10

### Directions

Please turn in this assignment by emailing them to me . Please use the subject of "Physics 222 HW10" for this assignment (if you use the link above, the subject will be added automatically). Please attach the source code to any programs that you write for this assignment. If you write more than one program, attach each separately. When answering the questions themselves feel free to answer directly in the body of your message (or attach your answers).

1. #### Number fun

Write a program that reads in integers from a file and puts them in an array Assume that the integers range in size between -999,999 and 999,999. The first number in the input file is the number of numbers that your program should read in (the size of the array). The program should then pass that array to the following functions:

1. A function that prints the numbers to the screen with the digits reversed — 1234 goes to 4321. Each number should be on its own line. There are at least two relatively easy ways to do this - use division by powers of ten and remainders to pull out the digits, or convert the integers to strings and reverse them.
2. A function that prints the square root of the numbers to the screen, with three numbers printed per line. Your program should take care of the case of negative integers by printing "i" ( for imaginary) after their square roots.
3. A function that takes in your array, and sends back a smaller array that only contains the numbers in your list whose absolute value are not prime. (This function should call your function from a previous assignment that checked one integer to see if it was prime. Copy and paste that previous function, and use it unchanged. You will have to write the rest of the function that calls the old prime checker.) The array that you send back should overwrite the initial array. Do not forget that you have to keep track of the array size for the new array.
4. Another function that takes the returned array of the previous function, and finds whether the sum of the digits of each number is odd or even. (eg 15: 1+5 = 6 = even, 36: = 3+6=9= odd). Use the absolute value of the numbers when you are doing this calculation.Like the previous function, this function will return a new array that only has numbers with odd sums of digits in it. It should also return the size of the new array. In this case the new array should not overwrite the old one.
Finally, your program will write to a file with ".out" added to the input file name (e.g. if the input file is "nums1", the output file is "nums1.out"). The first line of the output file should be the be the number of integers in the final array created by the last function. Then the file should contain a list of all of those numbers, one per line.

For input, your program should take the files nums1, nums2, and numsthree.

For this program, you should send in your programs output files and files with the output sent to the screen by your program for the files linked above. To save the output, I suggest that you use redirection:

```  num_fun  >nums1.txt
```
Note that when you run your program this way you will not be able to see any questions that your program asks, but you still will need to answer them.

7.3, 7.10