Wednesday, 20 November 2013

C-Program to Interchange the diagonals of a matrix

#include<stdio.h>
main()
{
int a[50][50],m,n,i,j,d1=0,d2=0,t;
  printf("Enter no. of rows and columns(order)\t");
  scanf("%d%d",&m,&n);
  printf("Enter the elements of matrix:\n");
  if(m==n)
  {
    for(i=0; i<m; i++)
    for(j=0; j<n; j++)
          scanf("%d",&a[i][j]);
  printf("matrix representation of above elemnts is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0,j=n-1;i<m||j>=0;i++,j--)
{
t=a[i][i];
a[i][i]=a[i][j];
a[i][j]=t;
}
printf("\n\nthe new matrix after interchanging is\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
}
else
  printf("This program is only applicable to square matrices!!!");
 
}




sakoncepts.blogspot.in
output



No comments:

Post a Comment