Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming The program shall perform the following functions in order asimplemented within the main() function: (a) Read in 20 float values from the terminal

C programming

The program shall perform the following functions in order asimplemented within the main() function:

(a) Read in 20 float values from the terminal and place them in an array.

(b) In the main function, create a second array of integer values. For each value in float array, convert as follows:

o Truncate the float value to an integer.

o Convert all integers to positive values by taking their absolute values.

o Convert these positive integers to numbers in the range 0,,15 by implementing the mod operation (i.e. number mod 16).

(c) Print out the values of each array on their line using the float_display_array and integer_display_array functions.

(d) For each integer, print out the number of 1 bits in the resulting binary representation by calling 2 the function countBits.

(e) Sort the integer array using the integerQuickSort function. Print out the sorted integer array again using the showInts function.

(f) Create two functions that take an array and prints out the number of even values. The first function float_evens should ignore the part of the number to the right of the decimal point to determine if it is even. The second function integer_evens should count the number of even numbers as normal. Call both of these functions from the main function inside a single print statement annotating the returned values.

(g) Write a function most_values to figure out which values occur in the integer array calculated in the preceding step most frequently. The function will receive three parameters: o arr - the array itself o range - the number of elements in the array o maxval - the largest possible value in the array The function will print out the value which occurs the most times in the array. If there are more than one that occur as the highest number, print them all. Hint: You can assume that maxval will never exceed 16.

(h) Cast each integer to an unsigned short type and compute a number with bits reversed by calling the reverseBits function. Print out a binary representation of each of the numbers by calling the binaryString on two string arrays and printing out the resulting text.

Try to use bit-wise operators for each of the functions mentioned above. Specifically, use bit-wise operators for the following:

a) calculating the mod and absolute values

b) countBits function (where you keep dividing by 2)

c) reverseBits function

d) finding even numbers

e) swapping variables in sorting without temporary variables You can truncate floats to ints using a type-cast. The goal is to not use functions from the math.h library

image text in transcribed

unction Parameters escription float display A reference to the array of floats This function prints out an array of floats on a and an integer length of the array.single line. The display width should be the same for each value. The float should only print the first array two numbers to the right of the decimal point. integer displa A reference to the array of integers This function prints out an array of integers on a and an integer length of the array. |single line. The display width will be the same for arra each value. ction s receive a unction should return the number of even integer even reference to an array of integers values in the array passed. and the array length float evens This should receive a reference to The function should return the number of even values of the array passed (truncate float value to its lowest integer). an array of floats and the array en countBits receive an integer to unction should return the nu of nonzero count bits from. bits in the number. Note that any negative sign should be ignored for the purposes of c ounting bits. reverseBits receive an unsi unction return the number (in integer short integer of the number toformat) whose bits are reversed, i.e., the top bit of the original number is thebottom bit of the number, the second from the top bit of the original number is the second to the bottom bit of everse retu the returned number binaryString ould receive a pointer to a s function shouldf text string with a string, a length and a number to convert to binary binary representation of the number suitable for rinting. If the string is too long, just print as man igits as is possible (don't forget to NUIL terminate the string) most values ction s receive a unction should return the valuels) that occurs reference to the integer array, the the most. number of elements and the maximum possible value integerQuickS This function should receive a ort unction sort the values in arra the index of a left and right use the algorithm listed on the element to sort reference to the integer array and using a quick sort from lowest to highest. You can Wikipedia page corresponding

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

find all matrices A (a) A = 13 (b) A + A = 213

Answered: 1 week ago

Question

1. In what ways has flexible working revolutionised employment?

Answered: 1 week ago