this is pretty stupid, but it bothers me. when i a.out, this is what i get:
Here is Homework 7:
Month 0: x[] = { 0.200 0.300 0.500} <-------
Month 1: x[] = { 0.270 0.380 0.350 }
Month 2: x[] = { 0.327 0.398 0.275 }
Month 3: x[] = { 0.369 0.394 0.238 }
Month 4: x[] = { 0.397 0.384 0.219 }
Month 5: x[] = { 0.417 0.374 0.209 }
Month 6: x[] = { 0.429 0.366 0.205 }
Month 7: x[] = { 0.437 0.361 0.202 }
Month 8: x[] = { 0.442 0.357 0.201 }
Month 9: x[] = { 0.445 0.354 0.201 }
Month 10: x[] = { 0.447 0.353 0.200 }
Month 11: x[] = { 0.448 0.352 0.200 }
Month 12: x[] = { 0.449 0.351 0.200 }
as you can see where the arrow is, all of the lines have a space between the last number and the } except month 0. why?
here's my code:
Code:
#include <stdio.h>
void prob1(void);
int main(void)
{
prob1();
exit(0);
}
void prob1(void)
{
double a[3][3]={0.8, 0.2, 0.1,
0.1, 0.7, 0.3,
0.1, 0.1, 0.6};
double x0[3]={0.2, 0.3, 0.5 }, x1[3];
double sum;
int month, row, col, rows=3, cols=3;
printf("\nHere is Homework 7:\n");
printf("Month %2d: x[] = {", 0);
for(row=0; row<rows; row++) printf(" %6.3f", x0[row]);
printf("}\n");
for(month=1; month<=12; month++ ){
printf("Month %2d: x[] = {", month);
for(row=0; row<rows; row++){
for(col=0, sum=0.0; col<cols; col++){
sum += a[row][col]*x0[col];
}
x1[row] = sum;
}
for(row=0; row<rows; row++) printf(" %6.3f", x1[row]);
printf(" }\n");
for(row=0; row<rows; row++) x0[row] = x1[row];
}
printf("\n");
return;
}