GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 30-Jun-2004, 10:32
Rosmayati's Avatar
Rosmayati Rosmayati is offline
New Member
 
Join Date: May 2004
Location: Malaysia
Posts: 20
Rosmayati is on a distinguished road

for looping prob


I'VE TRIED THE FOR LOOPING AS BELOW, BUT THE OUTPUT I'VE GOT DIDN'T APPEAR AS I WANT. I THINK THERE'S SOMETHING WRONG WITH THE LOOP CONDITION. ANYBODY THERE CAN HELP ME. THANKS IN ADVANCE

the source code:

CPP / C++ / C Code:
for (i1=0; i1<nrow; i1++)
{
	for (i2=0; i2<i1; i2++);
   {
   	for (j=0; j<ncol; j++)
      {
      	var1 = (A[i1][j] - A[i2][j]);
         var2 = pow(var1,2);
      	Adiss[i1][i2] = Adiss[i1][i2]+ (0.5*var2);
         fprintf(adissfile, "i1[%d]j[%d]: %lf\ti2[%d]j[%d]: %lf\ti1[%d]i2[%d]: %lf\n", i1, j, A[i1][j], i2, j, A[i2][j],i1, i2, A[i1][i2]);
      }
      //Fill the other half of the array
      Adiss[i2][i1] = Adiss[i1][i2];
   }
}

the output
i1[0]j[0]: 5.100000 i2[0]j[0]: 5.100000 i1[0]i2[0]: 5.100000
i1[0]j[1]: 3.500000 i2[0]j[1]: 3.500000 i1[0]i2[0]: 5.100000
i1[0]j[2]: 1.400000 i2[0]j[2]: 1.400000 i1[0]i2[0]: 5.100000
i1[0]j[3]: 0.200000 i2[0]j[3]: 0.200000 i1[0]i2[0]: 5.100000
i1[1]j[0]: 4.900000 i2[1]j[0]: 4.900000 i1[1]i2[1]: 3.000000
i1[1]j[1]: 3.000000 i2[1]j[1]: 3.000000 i1[1]i2[1]: 3.000000
i1[1]j[2]: 1.400000 i2[1]j[2]: 1.400000 i1[1]i2[1]: 3.000000
i1[1]j[3]: 0.200000 i2[1]j[3]: 0.200000 i1[1]i2[1]: 3.000000
i1[2]j[0]: 4.700000 i2[2]j[0]: 4.700000 i1[2]i2[2]: 1.300000
i1[2]j[1]: 3.200000 i2[2]j[1]: 3.200000 i1[2]i2[2]: 1.300000
i1[2]j[2]: 1.300000 i2[2]j[2]: 1.300000 i1[2]i2[2]: 1.300000
i1[2]j[3]: 0.200000 i2[2]j[3]: 0.200000 i1[2]i2[2]: 1.300000
i1[3]j[0]: 4.600000 i2[3]j[0]: 4.600000 i1[3]i2[3]: 0.200000
i1[3]j[1]: 3.100000 i2[3]j[1]: 3.100000 i1[3]i2[3]: 0.200000
i1[3]j[2]: 1.500000 i2[3]j[2]: 1.500000 i1[3]i2[3]: 0.20000
  #2  
Old 30-Jun-2004, 11:39
dabigmooish's Avatar
dabigmooish dabigmooish is offline
Member
 
Join Date: May 2004
Location: Baltimore (middle of Canton)
Posts: 165
dabigmooish will become famous soon enough
What output were you hoping for?

The second loop (the first nested loop) won't even run the first time(while i1 = 0). Maybe thats where your problem comes in.That means first time var1 is set its gonna equal: var1 = A[1][0] - A[0][0] the second time its gona be A[1][1] - A[0][1] and so on. If this is what you want you could just leave the second loop out and put:

CPP / C++ / C Code:
for (i1=0; i1<nrow; i1++)
{
     for (j=0; j<ncol; j++)
     {
          var1 = (A[i1][j] - A[i1-1][j]);
          var2 = pow(var1,2);
          Adiss[i1][i1-1] = Adiss[i1][i1-1]+ (0.5*var2);
          fprintf(adissfile, "i1[%d]j[%d]: %lf\ti2[%d]j[%d]: %lf\ti1[%d]i2[%d]: %lf\n", i1, j, A[i1][j], i1-1, j, A[i1-1][j],i1, i1-1, A[i1][i1-1]);
     }
      //Fill the other half of the array
      Adiss[i2][i1] = Adiss[i1][i2];
}
__________________
"To argue with a person who has renounced the use of reason is like administering medicine to the dead."
-Thomas Paine
www.sullivan-county.com/deism.htm
 

Recent GIDBlogPrepping for deployment by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help/advise on HDD prob [Ci] Luigi Computer Hardware Forum 9 28-Aug-2004 14:52
Prob. w/ Initalizing Data Members to 0 BobbyMurcerFan CPP / C++ Forum 5 26-Jun-2004 20:01
writing into file prob belludandy C Programming Language 0 15-Nov-2003 19:25
vector prob nattylife CPP / C++ Forum 1 15-Nov-2003 07:41

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 19:47.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.