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

int main(void) { //Local Declarations float a; float b; float c; float d; float

ID: 3648498 • Letter: I

Question


int main(void)
{

//Local Declarations

float a;
float b;
float c;
float d;
float e;
float f;
float g;
float h;
float i;
float j;
float sum1;
float sum2;

// Statements

printf("Please enter 10 numbers: ");
scanf("%f %f %f %f %f %f %f %f %f %f", &a,&b,&c,&d,&e,&f,&g,&h,&i,&j);


sum1 = a + b + c + d + e;
sum2 = f + i + g + h + i;

printf(" The numbers you have entered are: ");

printf(" %4.0f %4.0f ", a, j);
printf("%4.0f %4.0f ", b, i);
printf("%4.0f %4.0f ", c, h);
printf("%4.0f %4.0f ", d, g);
printf("%4.0f %4.0f ", e, f);
printf(" %5.0f %5.0f ", sum1, sum2);



return 0;

} //main

This is my program that the user enters ten numbers and it seperates those numbers into to different columns. Also, the sums of each column is printed at the bottom of each column.
I was wondering if anyone knows how to right justify the results so that if the numbers are 4 digits long, they still print in the midle of the title "The numbers you have entered are". Also, is there anyway to have a title that says total at the bottow, yet the numbers still line up wih the rest of the numbers.

we are using a ssh client and gcc compiler.


Explanation / Answer

int main() { float a,b,c,d,e,f,g,h,i,j,sum1,sum2,total; printf("Please enter 10 numbers: "); scanf("%f %f %f %f %f %f %f %f %f %f", &a,&b,&c,&d,&e,&f,&g,&h,&i,&j); sum1 = a + b + c + d + e; sum2 = f + i + g + h + i; total=sum1+sum2; printf(" The numbers you have entered are: "); printf("%4.0f %4.0f ", a, j); //here 0f specifies it will convert float to nearest int we can remove 0 for float printf("%4.0f %4.0f ", b, i); printf("%4.0f %4.0f ", c, h); printf("%4.0f %4.0f ", d, g); printf("%4.0f %4.0f ", e, f); printf(" %5.0f %5.0f ", sum1, sum2); printf(" %5.0f ",total); return 0; }