Thread: compiler stops working

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    1

    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");
    }
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read this: << !! Posting Code? Read this First !! >> Then come back here and press Edit, and fix your code. No one wants to read something that looks like that.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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!!

    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;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [resolved] internal compiler error...
    By bling in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2008, 12:57 PM
  2. Replies: 8
    Last Post: 01-18-2008, 04:06 AM
  3. Replies: 4
    Last Post: 01-13-2008, 02:14 AM
  4. Compiler not working...
    By Geo-Fry in forum C++ Programming
    Replies: 1
    Last Post: 02-21-2003, 10:58 PM
  5. Bad code or bad compiler?
    By musayume in forum C Programming
    Replies: 3
    Last Post: 10-22-2001, 09:08 PM