首页 > 用户发贴区 > 编程问题提问区 > 为什么此程序运行几次后便自动跳出?请帮帮忙!
2008
04-14

为什么此程序运行几次后便自动跳出?请帮帮忙!

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
int THE_WIDE_I=20,THE_GRID_X=420;


int irand_num(int MAX)
{
 int num;


 num=int(MAX*rand()/(pow(2,15)-1));
 return num;
}


void main/*FindLatticeSlip*/(/*int lengthNoSlip, int lengthSlip,*/ bool theMode, int slipArray[])
{   
//int slipArray[THE_GRID_X-THE_WIDE_I+1];


int lengthNoSlip1,lengthSlip1;
//int lengthNoSlip2,lengthSlip2;


int length1=0,length2=0;
int i;
//if (theMode==0)
//{
 srand( (unsigned)time( NULL ) );
     for(int x=0;x<100;x++)
   {//srand( (unsigned)time( NULL ) );
  //int y=rand()%20+1;
      int y=irand_num(20);
         printf(“x=%d\n”,x);
           printf(“y=%d\n”,y);
    
          if (x%2==0)
    {
     if(length1+y<=THE_GRID_X-THE_WIDE_I)
     {
      lengthNoSlip1=y;
         printf( ” lengthNoSlip1=%d\n”, lengthNoSlip1 );
     
      slipArray[length1]=3;printf( ” slipArray[]=%d\n”, slipArray[length1] );
    
      for(i=length1+1;i<length1+y;i++)
      { slipArray[i]=0;
      printf( ” slipArray[]=%d\n”, slipArray[i] );
      }
      length1=length1+y;
                  printf( ” length1=%d\n”, length1 );
     }
     else //if(length1+y>THE_GRID_X-THE_WIDE_I)
     {
      lengthNoSlip1=400-length1;
                  printf( ” lengthNoSlip1=%d\n”, lengthNoSlip1 );
     
      for(i=length1+1;i<THE_GRID_X-THE_WIDE_I+1;i++)
      { slipArray[i]=0;}
      length1=THE_GRID_X-THE_WIDE_I;
                  printf( ” length1=%d\n”, length1 );
                
     // break;
     }
    }
           else if(x%2==1)
           {
      if(length1+y<=THE_GRID_X-THE_WIDE_I)
      {
       lengthSlip1=y;
          printf( ” lengthSlip1=%d\n”, lengthSlip1 );
                   slipArray[length1]=2;printf( ” slipArray[]=%d\n”, slipArray[length1] );


                   for(i=length1+1;i<length1+y;i++)
       {slipArray[i]=1;printf( ” slipArray[]=%d\n”, slipArray[i] );}


                   length1=length1+y;
                   printf( ” length1=%d\n”, length1 );
                  
                  
      }
      else //if(length1+y>THE_GRID_X-THE_WIDE_I)
      {
       lengthSlip1=400-length1;
       printf( ” lengthSlip1=%d\n”, lengthSlip1 );
                   for(i=length1+1;i<THE_GRID_X-THE_WIDE_I+1;i++)
      {slipArray[i]=0;}
                   length1=THE_GRID_X-THE_WIDE_I;
                   printf( ” length1=%d\n”, length1 );
                  
      // break;
      }
     }
    
   }



留下一个回复