Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello all, I am writing this in C in Unix, the top command window is my output,

ID: 3605724 • Letter: H

Question

Hello all, I am writing this in C in Unix, the top command window is my output, and the bottom one is where I need to make my look like it. I did get my code to print out the same thing. But the thing is spacing, I dont know how to make the spacing like the bottom window command. I can't think of away to make spacing to work for all number but still stay alligned. Please help

Here are the codes for the first 3 lines of the bar chart. I thought putting 5 up here would be too long, since If i can fix 1, i can go back and fix the others.

//bar chart//category 1 highest group

int gt;

int ou=0;

for(gt=0;gt<=length;gt++){/*this function is to count how many numbers

falls in each group*/

if(arr[gt]<=A[0] && arr[gt]>=B[0]){

ou++;

}

}

int o;

fprintf(output,"%*d-%*d (%*d): ",3,B[0],3,A[0],2,ou);

for(o=0;o<=length;o++){

if(arr[o]<=A[0] && arr[o]>=B[0]){

fprintf(output,"x");

}

}

fprintf(output," ");

//category 2/second highest group

int hou=0;

for(gt=0;gt<length;gt++){/*this function is to count how many numbers

falls in each group*/

if(arr[gt]<=A[1] && arr[gt]>=B[1]){

hou++;

}

}

int h;

fprintf(output,"%*d-%*d (%*d): ",3,B[1],3,A[1],2,hou);

for(h=0;h<length;h++){/*this function to count and print out an x for each number it

found in this min B[] and max A[] particular group*/

if(arr[h]<=A[1] && arr[h]>=B[1]){

fprintf(output,"x");

}

glue.umd.edu - PuTTY 117-20 ( 6): xxxxxx 13- 16 (5): xxxxx 9- 12 6): xxxxxx 5- 8 4): xxxx Minimum: 0 Maximum: 20 Average: 9.800 Standard Deviation: 6.896 The most frequent value is 20 and it appears 4 times The first multiple of 6 is 12. It is the 3st number 25th percentile: 3.000 Median percentile: 11.000 75th percential: 15.000 "out.txt" 14 lines, 347 characters glue.umd.edu - PuTTY 17-20 6): xxxxxx 13-16 ( 5): xxxxx 9-12 6): xxxxxx 5-8 4): xxxx Minimum: 0 Maximum: 20 Average: 9.800 Standard Deviation: 6.896 The most frequent value is 20 and it appears 4 times The first multiple of 6 is 12. It is the 3rd number 25th percentile: 3.000 Median: 11.000 75th percentile: 15.000

Explanation / Answer

You need to pad with leading space if number do not occupy given count of digit for left side and right pad for right side

so %2d will pad "9" to "09" and "17" to 17 on left side and on right side "9" will be "9 " and "17" will be "17"

fprintf(output,"%2d-%-2d (%2d): ",B[0],A[0],ou);

so it will print

7-9

17-19

If you have more than 2 digit number then you have to compute max digits and then use that in printfstatement

fprintf(output,"%*d-%-*d (%*d): ", max_left_digit_count, B[0], max_right_digit_count, A[0], max_bracket_digit_count, ou);

int gt;
int ou=0;
for(gt=0;gt<=length;gt++){/*this function is to count how many numbers
falls in each group*/
if(arr[gt]<=A[0] && arr[gt]>=B[0]){
ou++;
}
}
int o;
fprintf(output,"%2d-%-2d (%2d): ",B[0],A[0],ou);
for(o=0;o<=length;o++){
if(arr[o]<=A[0] && arr[o]>=B[0]){
fprintf(output,"x");
}
}
fprintf(output," ");
//category 2/second highest group
int hou=0;
for(gt=0;gt<length;gt++){/*this function is to count how many numbers
falls in each group*/
if(arr[gt]<=A[1] && arr[gt]>=B[1]){
hou++;
}
}
int h;
fprintf(output,"%2d-%-2d (%2d): ",B[1],A[1],hou);
for(h=0;h<length;h++){/*this function to count and print out an x for each number it
found in this min B[] and max A[] particular group*/
if(arr[h]<=A[1] && arr[h]>=B[1]){
fprintf(output,"x");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote