Hello everyone i'm a new member , i need ur help with this code ,
i want to write a for loop that assigns the 3rd row of the array to 0,, and then print out the array after setting the 3rd row to 0.

# include <iostream.h>
int main ()
{
int BL [5][4];
int i,j;
for (i=0;i<5;i++)
	 {  
                  for (j=0;j<4;j++)
	 {
	  BL [i][j]=i+j;
		cout<<BL[i][j];
	  }
	 cout<<endl<<endl;
	 }

return 0 ;
}

well in the code set i = 2 (for 3rd row ) and iterate only for the j column and set b[j] = 0 ;


i =2 ;  // for the 3rd row 
for( j = 0 j<5;j++)
b[i][j] = 0;

i guess this should work

Edited 7 Years Ago by rahul8590: forgot to set the value for i

this code is only to set the 3rd row to zero .
Can u post the new code where u have placed the code i wrote above ?
It would be easier for me to diagnose the problem.

i figured out the answer , thank you very much raul :)
the right code is

#include<iostream.h>

int main ()
{
int BL[5][4];
int i,j;

for(i=0;i<5;i++)
  {for(j=0;j<4;j++)
      { BL[i][j]=i+j;
      cout<<BL[i][j]<<" ";
        }
  cout<<endl;
  }
cout<<endl<<endl;

for(i=0;i<5;i++)
  {if(i==2)
     {
      for(j=0;j<4;j++)
        {BL[2][j]=0;
         cout<<BL[2][j]<<" ";
        }
      i++;
      cout<<endl;
     }
  for(j=0;j<4;j++)
      { BL[i][j]=i+j;
      cout<<BL[i][j]<<" ";
      }
  cout<<endl;
  }
return 0;
}

Edited 3 Years Ago by Reverend Jim: Fixed formatting

please use the code tags while posting ur code , besides instead of this

for(i=0;i<5;i++)
{if(i==2)
{
for(j=0;j<4;j++)
{BL[2][j]=0;
cout<<BL[2][j]<<" ";
}

u can write it this way .

for ( j=0;j<4;j++)
b[2][j] = 0;

u can eliminate the other lines of ur code.