I'm writing a code in C to solve partial differential 2D heat equations through Gauss-Seidel Iterations. I was using TurboC++ to compile and the program ran perfectly, but when I switched to Code::Blocks and compiled and ran the program, all I get is a black screen. I'm a beginner in C programming and can't figure out why I'm not getting any output on the screen. Any help would be greatly appreciated!
I have written the following code :
Code:
#include <stdio.h>
int i,j,imax=21,jmax=41,n=0;
float dx=0.05,dy=0.05,T1=150,T2=0,T3=0,T4=0,error,error_max=0.01,T_o ld,T[22][42];
/*Initialization of T at interior points*/
for(i=1;i<=imax;i++)
for(j=1;j<=jmax;j++)
T[i][j]=0;
/*T at boundary points*/
for(j=1;j<=jmax;j++)
{ T[1][j]=T2;
T[imax][j]=T4;
}
for(i=1;i<=imax;i++)
{ T[i][1]=T1;
T[i][jmax]=T3;
}
/*Gauss-Seidel Iterations*/
{ error=0;n++;
for(i=2;i<imax;i++)
{ for(j=2;j<jmax;j++)
{ T_old=T[i][j];
T[i][j]=(dy*dy*(T[i+1][j]+T[i-1][j])+dx*dx*(T[i][j+1]+T[i][j-1]))/(2*(dx*dx+dy*dy));
if(T_old>T[i][j])
error=error+(T_old-T[i][j]);
else
error=error+(T[i][j]-T_old);
}
}
}while(error>error_max);
/*results*/
printf("i \t j \t T (Gauss-Seidel)");
for(j=1;j<=jmax;j++)
printf("\n 11 \t %d \t %f",j,T[11][j]);
printf("\n error = %f,\n n = %d", error,n);