Search This Blog

Thursday, October 13, 2011

Write a pogram to display a matrix whose elements are x(i,j)=i+j when i!=j and x(i,j)=0 when i=j

   1:  #include<stdio.h>
   2:  #include<conio.h>
   3:  void main()
   4:  {
   5:  int i,j,x[3][4];
   6:  printf("Desired 3x4 matrix is:\n\n");
   7:  for(i=0;i<3;i++)
   8:  {
   9:  for(j=0;j<4;j++)
  10:  {
  11:  if(i!=j)
  12:  x[i][j]=i+j;
  13:  else if(i==j)
  14:  x[i][j]=0;
  15:  printf("%d ",x[i][j]);
  16:  }
  17:  printf("\n");
  18:  }
  19:  getch();
  20:  }

No comments:

Post a Comment