Wednesday, 20 August 2014

// CODE TO FIND OUT THE ADDRESS OF THE ELEMENT aij FOR DIAGONAL MATRIX OF ROW MAJOR ORDER


#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,n=0,m,r,c,r1,c1,add=0;
printf("\n Enter the rows of the matrix:");
scanf("%d",&r);
printf("\n Enter the column of the matrix:");
scanf("%d", &c);
if(r==c)
{
printf("\n Enter the row of the element:");
scanf("%d",&r1);
printf("\n Enter the column of the element:");
scanf("%d",&c1);
printf("\n Enter the base address:");
scanf("%d", &m);
for(i=1;i<=r1;i++)
{
for(j=1;j<=c1;j++)
{
n=n+2+2*(i-2)+j;
}
}
add=n+m-1;
printf("\n The address of a[%d][%d] in row major order of a tridiagonal matrix is = %d",r1,c1,add);
}
else
{
printf("\n Please enter the order of a square matrix...");
}
getch();
return 0;
}

//OUTPUT


 Enter the rows of the matrix:3

 Enter the column of the matrix:3

 Enter the row of the element:2

 Enter the column of the element:3

 Enter the base address:200

 The address of a[2][3] in row major order of a tridiagonal matrix is = 217

No comments:

Post a Comment

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