Lesson goal: Histogram the digits of Pi

Previous: Arrays and histograms | Home | Next: Histogramming uniform rnd nums

In a past lesson we counted the occurrences of each digit in $\pi$. This lesson is a bit of a repeat of that lesson, but does an analysis using arrays and the creation of a professional looking histogram chart.

In this case, each digit of $\pi$ is read from the variable bigpi. Each digit is used as an index into an array called hist that keeps track of the number of times a given digit occurs in bigpi. Another array called digit is used to seed the horizontal axis of the histogram, as it is loaded with the numbers from 0 to 9, which are the possible digits in $\pi$.

Now you try. Fix the digit[i] = so digit will hold the numbers from 0 to 9. Fix the hist[i]= line so that all counts start at zero. Lastly, fix the hist[d] = line so that it is increased by one inside of the if statement.

Type your code here:


See your results here: