# Simple program...simple problem?

• 03-12-2009
Simple program...simple problem?
Don't know why but it dosent print out the right numbers, and prints out numbers that dont make any sence at all

Code:

```#include <stdio.h> # define MAX 21 int main(void){ double Top_Temp,Right_Temp,Bottom_Temp , Left_Temp, Tolerance; int Grid_Colums,Grid_Rows, i,j,Iterations; double Log[MAX][MAX]; printf("Enter the top side temp:"); scanf("%lf",&Top_Temp); printf("Enter the right side temp:"); scanf("%lf",&Right_Temp); printf("Enter the bottom side temp:"); scanf("%lf",&Bottom_Temp); printf("Enter the left side temp:"); scanf("%lf",&Left_Temp); printf("How many rows in the grid?"); scanf("%i",&Grid_Rows); printf("How many columns in the grid?"); scanf("%i",&Grid_Colums); printf("\n"); printf("\n"); printf("\n"); printf("\n"); printf("\n"); ///preset all values to 0 or whatever the sides are for(i=1;i<=Grid_Colums;i++){ for(j=1;j<=Grid_Rows;j++){ if(j==1){ Log[i][j]=Left_Temp; } else if(i==1 && j!=1 && j!=Grid_Rows){ Log[i][j]=Top_Temp; } else if(j==Grid_Rows){ Log[i][j]=Right_Temp; } else if(i==Grid_Colums && j!=1 && j!=Grid_Rows){ Log[i][j]=Bottom_Temp; } else{ Log[i][j]=0.0; } } } for(i=1;i<=Grid_Colums;i++){ for(j=1;j<=Grid_Rows;j++){ if(j==1){ } else if(i==1 && j!=1 && j!=Grid_Rows){ ///do nothing } else if(j==Grid_Rows){ //do nothing } else if(i==Grid_Colums && j!=1 && j!=Grid_Rows){ //do nothing } ///the avarege of all the spaces around the  the current space using (a+b+c+d+e+f+g+h+i)/9= average else{Log[i][j]=(((Log[1-i][1-j])+(Log[1-i][j])+(Log[1-i][1+j])+(Log[i][1-j])+(Log[i][j])+(Log[i][1+j])+(Log[1+i][1-j])+(Log[1+i][j])+(Log[1+i][1+j]))/9); } } } ///prints grid for(i=1;i<=Grid_Colums;i++){ for(j=1;j<=Grid_Rows;j++){ printf("%8.2lf",Log[i][j],i,j); } } printf("\n"); return 0; }```
here is an example of the out put

Quote:

Enter the top side temp:34
Enter the right side temp:45
Enter the bottom side temp:56
Enter the left side temp:2
How many rows in the grid?10
How many columns in the grid?10

2.00 34.00 34.00 34.00 34.00 34.00 34.00 34.00 34.00 45.00
2.003846176819139386240495146280763901266114230000 00000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
0000000.00 0.003951937901898015471105687508780148206111037000 0000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000.00395193790189801547110568750878 014820611103700000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
0000000000000000000.00 0.003786320267709942753891208951542362435293359000 0000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000.00773825675947454695 904703396065433099033889100000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
0000000000000000000000000000000.003951936491764604 692929035995985754708420099000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
000000000000000000000000000000000.00 45.00 2.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 10.00 45.00 2.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 10.00 45.00 2.006185387601747340982356416560
92461900413940200000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000.00 0.00 0.00 0.00 0.00 0.00 0.00 10.
00 45.00 2.006185387601747340982356416560924619004139402000 0000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 000000000000000000000000000000
00000000000000000000000000000000000000000000000000 0000000000000000000.00 12.44
12.44 12.44 12.44 12.44 12.44 16.22 45.00 2.00 56.00 56.00
56.00 56.00 56.00 56.00 56.00 56.00 45.00
• 03-12-2009