Wednesday, 27 August 2014

//Address of element a[ij] for diagonal matrix of column major order
#include<stdio.h>
 #include<conio.h>
 main()
 {
  int a,b
  int n=0,m,row,col,row1,col1,add=0;
  printf("\n Enter rows of the matrix:");
  scanf("%d",&row);
  printf("\n Enter column of the matrix:");
  scanf("%d", &col);
  if(row==col)
  {
   printf("\n Enter row of the element:");
   scanf("%d",&row1);
   printf("\n Enter the column of the element:");
   scanf("%d",&col1);
   printf("\n Enter the base address:");
   scanf("%d", &m);
   for(a=1;a<=row1;a++)
   {
    for(b=1;b<=col1;b++)
    {
      n=n+2+2*(b-2)+a;
    }
   } 
   add=n+m-1;
   printf("\n The address of a[%d][%d] in column major order of a tridiagonal matrix is = %d",row1,col1,add);
  }
  else
  {
   printf("\n Please enter the order of a square matrix");
  }
  getch();
  return 0;
 }
Output:
 Enter rows of the matrix:10
Enter column of the matrix:10
Enter row of the element:9
Enter column of the element:8
Enter base address:255
The address of a[9][8] is 1118

No comments:

Post a Comment

Note: only a member of this blog may post a comment.