有道关于C语言的题目,大家一定要帮帮小妹啊……不好意思是英文的……

来源:百度知道 编辑:UC知道 时间:2024/06/30 06:15:26
Question

This option will invoke a single function that accepts up to 10 integers and then optionally prints a horizontal or vertical histogram for the given data. A sample horizontal histogram is show below. A vertical histogram will be identical but with the plot shown below rotated 90 degrees anti-clockwise.

Any number that exceeds 10 must be plotted with 10 "*" and the number displayed at the end (see the plot for the number 20). The length of the data axis must be limited by the number of entered "number" entries.

Example:

Enter numbers: 20 5 2
Orientation (H = horizontal, V = vertical): H

0 5 10
+----+----+
|**********20
|*****
3|**

Start-up Code:

/* Function histogram() will receive an array of integers and print a
* horizontally or vertically-oriented histogram. This function will
* be used in menu option 5.
*/
void histogram

/* since u didnt mention what compiler u prefer, i would like to use MinGW. Both Hor and Ver */

void histogram(int * frequencyTab, int sizeTab, char orientCode) {
int i = -1, j = 0;
switch (orientCode) {
case 'h':
case 'H': {
printf("Enter numbers:");
/* i = -1 */
while (i++ < (sizeTab < 9 ? sizeTab : 9))
printf(" %d", frequencyTab[i]);

printf("\nOrientation (H = horizontal, V = vertical): %c\n", orientCode);

printf("0 5 10\n+----+----+\n");

for (i = 0; i < 10 && i < sizeTab; i++) {
printf("|");

/* j = 0 */
while (j++ < (frequencyTab[i] < 10 ? frequencyTab[i] : 10)
&& frequencyTab[i] >= 0)
printf("*");

if (frequencyTab[i] > 10)
printf("%d\n", frequencyTab[i]);
else