-
compiler stops working
Hello ppl. I have wriiten a code in C to check the convergence of an iterative process. But when I run it in Turbo C without running it shows error- "nvtdm has stopped working". What could that be? And how to solve this problem?
#include<stdio.h>
#include<math.h>
#include<conio.h>
void main()
{
int n,m,limiter,i,j,z;
float s[100][100],s0[100][100];
float dt,dx,dy,tol,dfmax1,dfabs1;
limiter=50;
printf ("Enter no of grid points:", m);
scanf ("%d", &m);
printf ("Enter tolerence:", tol);
scanf ("%f", &tol);
printf ("Enter time step:", dt);
scanf ("%f", &dt);
n=(m-1);
dx = 1.0/(n-1);
dy = 1.0/(n-1);
for (i=0;i<=n;i++)
{
for (j=0;j<=n;j++)
{
s0[i][j]=0.0;
}
}
for (z=1;z<=limiter;z++)
{
for (i=1;i<n;i++)
{
for (j=1;j<n;j++)
{
s[i][j]=(s0[i-1][j]+s0[i][j-1]+s0[i+1][j]+s0[i][j+1]+1*dx*dx)/4;
}
}
dfmax1=0.0;
for (i=1;i<n;i++)
{
for (j=1;j<n;j++)
{
dfabs1= abs(s[i][j]-s0[i][j]);
if (dfabs1>dfmax1)
dfmax1=dfabs1;
}
}
printf ("%f ", dfmax1);
for (i=1;i<n;i++)
{
for (j=1;j<n;j++)
{
s0[i][j]=s[i][j];
}
}
if (dfmax1<tol)
{
break;
}
}
printf ("no of iterations for iner loop:%d\n ", z);
for (j=n;j>=0;j--)
{
for (i=0;i<=n;i++)
{
printf ("%f ", s0[i][j]);
}
printf ("\n");
}
}
-
Read this: http://cboard.cprogramming.com/c-pro...ead-first.html Then come back here and press Edit, and fix your code. No one wants to read something that looks like that.
Quzah.
-
Welcome to the forum akkiphadnis!
Please remember to use code tags around your program.
The program is simply finishing before you can see it, and the console environment, closes as well. That's what NTVDM is: The NT Kernels (includes WinXP) DOS Virtual Machine, that allows 32 Windows to run 16 bit programs (like Turbo C).
This is a version that fixes your problem. Note the excellent indentation!! :D
Code:
#include<stdio.h>
#include<math.h>
#include<conio.h>
int main(void)
{
int n,m,limiter,i,j,z;
float s[100][100],s0[100][100];
float dt,dx,dy,tol,dfmax1,dfabs1;
limiter=50;
printf ("Enter no of grid points:", m);
scanf ("%d", &m);
(void) getchar();
printf ("Enter tolerence:", tol);
scanf ("%f", &tol);
(void) getchar();
printf ("Enter time step:", dt);
scanf ("%f", &dt);
(void) getchar();
n=(m-1);
dx = 1.0/(n-1);
dy = 1.0/(n-1);
for (i=0;i<=n;i++)
{
for (j=0;j<=n;j++)
{
s0[i][j]=0.0;
}
}
for (z=1;z<=limiter;z++)
{
for (i=1;i<n;i++)
{
for (j=1;j<n;j++)
{
s[i][j]=(s0[i-1][j]+s0[i][j-1]+s0[i+1][j]+s0[i][j+1]+1*dx*dx)/4;
}
}
dfmax1=0.0;
for (i=1;i<n;i++)
{
for (j=1;j<n;j++)
{
dfabs1= abs(s[i][j]-s0[i][j]);
if (dfabs1>dfmax1)
dfmax1=dfabs1;
}
}
printf ("%f ", dfmax1);
for (i=1;i<n;i++)
{
for (j=1;j<n;j++)
{
s0[i][j]=s[i][j];
}
}
if (dfmax1<tol)
{
break;
}
}
printf ("no of iterations for iner loop:%d\n ", z);
for (j=n;j>=0;j--)
{
for (i=0;i<=n;i++)
{
printf ("%f ", s0[i][j]);
}
printf ("\n");
}
printf("\n\t\t\t press enter when ready");
(void) getchar();
return 0;
}