This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Programming Using C Homework 4 1. In Homework 3 you computed the histogram of an array, in which each entry represents one value of the array. We can generalize the histogram so that each entry, called a bin, represents a range of values in the initial array. Write a program that computes a histogram with a specified number of bins. Assume that the array holds one of N=20 possible values, from 0 to N1, and that N is a multiple of the number of bins. Your program should use this function: void histogram(int a, int n, int h, int n_bins); Example: Enter length: 10 Enter values: 2 1 2 0 2 3 1 0 11 0 Enter number of bins: 4 Histogram: 0... 9 1... 0 2... 1 3... 0 2. In this program you will simulate floating point additions as they are performed in the arithmeticlogic unit of the processor. Internally in a computer floating point numbers are stored using 32 bits. One bit, the leftmost, is used to represent the sign of the number: 0 for apositive number and 1 for a negative number. The remaining 31 bits are divided into the exponent (8 bits) and mantissa (23 bits). Conversion of an integer number into binary is done through repeated integer division by 2. Each time you save the remainder and concatenate it to the left of all other remainders you have previously found. For example, the decimal number 100 converted to binary is 1100100. This is a positive number so the sign bit will be 0. The mantissa is considered to be in scientific notation, so that a decimal point is imagined to the right of the leftmost 1 of the result. The exponent is 6 because the (imagined) decimal point has to slide 6 places to the left. The mantissa will start with 1100100 and will be followed by extra zeros to fill all of the 23 bits. The result is the following 32 bits: 1 00000110 11001000000000000000000 or 00000011011001000000000000000000 The exponent is an integer value so it is right justified in its space (ex tra zeros are added to the left to fil all 8 digits), while the mantissa...
View
Full
Document
This note was uploaded on 07/08/2011 for the course CGS 3460 taught by Professor Staff during the Summer '08 term at University of Florida.
 Summer '08
 Staff

Click to edit the document details