C Programming

# C Programming - Task One Write a funcTon that is passed...

This preview shows pages 1–3. Sign up to view the full content.

Task One: Write a function that is passed four integer inputs representing two different time periods (each expressed as a number of minutes and seconds). The function should calculate and return the difference between those two time periods (expressed as a number of seconds). Function prototype declaration: int SecondsBetween(int minuteA, int secondA, int minuteB, int secondB) Assumptions: You can assume that all four input values will be greater than or equal to 0. Example: int result1, result2, result3; result1 = SecondsBetween(5, 45, 7, 35); result2 = SecondsBetween(7, 35, 5, 45); result3 = SecondsBetween(0, 0, 10, 0); printf("%d %d %d \n", result1, result2, result3); Expected output: 110 110 600 Task Two: Write a function that is passed four inputs: an array of integers, the number of elements in the array, a low value and a high value. The function should calculate and return the sum of every element in the array that is between low and high (inclusive). In other words, you must calculate the sum of all values in the array that are greater than or equal to the value of low and less than or equal to the value of high. Any value that falls outside of that range should be ignored when you calculate the sum. Function prototype declaration: int SumInRange(int *values, int numValues, int low, int high) Assumptions: You can assume that there will be at least one element in the input array and that the value of low will be less than or equal to the value of high. Example: int numbers[11] = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}; int result1, result2, result3; result1 = SumInRange(numbers, 11, 0, 100); result2 = SumInRange(numbers, 11, -2, 2); result3 = SumInRange(numbers, 11, -4, -4); printf("%d %d %d \n", result1, result2, result3); Expected output: 15 0 -4 Task Three: Write a function that is passed two inputs: an array of integers, and the number of elements in the array. The function should return the number of distinct (i.e. different) values that exist in the array. Function prototype declaration :

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
int CountDistinct(int *values, int numValues) Assumptions: You can assume that there will be at least one element in the input array. Example : int valuesA[10] = {1, 2, 3, 2, 3, 2, 1, 2, 3, 2}; int valuesB[5] = {10, 100, 1000, 10000, 100000}; int valuesC[7] = {10, 11, 12, 13, 12, 11, 10}; int result1, result2, result3; result1 = CountDistinct(valuesA, 10); result2 = CountDistinct(valuesB, 5); result3 = CountDistinct(valuesC, 7); printf("%d %d %d \n", result1, result2, result3); Expected output: 3 5 4 Task Four Write a function to eliminate long sequences of consecutive characters in a word. Your function should take two inputs. The first is the word itself (i.e. a string), and the second is the maximum number of consecutive characters that are allowed to appear in the word - all consecutive characters exceeding this maximum should be eliminated. Your function will not return an output, but instead must modify the input word.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern