Thread: Mutidimensional Array problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    64

    Mutidimensional Array problem

    Code:
      for(trial = 0; trial < N; trial++)
        {
          b[trial] = 0.0;
          nstep = 0;
          t = 0.0;
          dis = 0;
          counter = 0;
          while(t < to)
    	{
    	  tau = tao * (1 + g * t); //tao, g, t are all entered at the command prompt
    	  dt = -log(a) * tau; //a is entered at the command prompt
    	  u = gsl_ran_flat (r, 0.0, 1.0);
    	  b[nstep * maxstep + dis]++; //maxstep is pre-determined, as is nstep
    	  if(u > a)
    	    {
    	      dis++;
    	    }
    	  t = t + dt;
    	  nstep++;
    	}
        }
      
      for(i = 0; i < maxstep; i++)
        {
          for(j = 0; j < maxstep; j++)
    	{
    	  fprintf(stderr, "%lf ", b[j * maxstep + i]);
    	}
    	  fprintf(stderr, "\n");
        }
    Code:
    20.000000 4.000000 0.000000 2.000000 1.000000 0.000000 0.000000 0.000000 
    0.000000 7.000000 2.000000 6.000000 5.000000 4.000000 2.000000 0.000000 
    0.000000 0.000000 0.000000 10.000000 4.000000 3.000000 2.000000 2.000000 
    0.000000 0.000000 0.000000 2.000000 10.000000 9.000000 8.000000 6.000000 
    0.000000 0.000000 0.000000 0.000000 0.000000 4.000000 5.000000 7.000000 
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 3.000000 4.000000 
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 1.000000 
    0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
    Supposedly, the sum of each column should be 20 (N = 20), however, column 2 and 3 do not add up to 20...why not?
    Last edited by vutek0328; 11-14-2006 at 05:55 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Array problem
    By TomBoyRacer in forum C++ Programming
    Replies: 3
    Last Post: 04-08-2007, 11:35 AM
  2. Replies: 6
    Last Post: 02-15-2005, 11:20 PM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Need desperate help with two dimensional array problem
    By webvigator2k in forum C++ Programming
    Replies: 4
    Last Post: 05-10-2003, 02:28 PM
  5. From stream/file to a string array problem
    By dradsws in forum C Programming
    Replies: 2
    Last Post: 10-01-2001, 06:24 PM