矩阵转置

一剑行天下 posted @ 2008年11月01日 23:24 in 数值分析 , 2000 阅读

 

#include<stdio.h>
int convert(int b[5][5]);
main()
{
        int a[5][5];
        int i,j;
        printf("input the number:\n");
        for(i=1;i<=5;i++)
                for(j=1;j<=5;j++)
                {
                        printf("\na[%d][%d]=",i,j);
                        scanf("%d",&a[i][j]);
                }       

        for(i=1;i<=5;i++)
        {
                for(j=1;j<=5;j++)
                        printf("%5d",a[i][j]);
                printf("\n");

        }
        convert(a);
        printf("now the new array is :\n");

        for(i=1;i<=5;i++)
        {
                for(j=1;j<=5;j++)

                        printf("%5d",a[i][j]);
                printf("\n");

        }
}


        int convert(int c[5][5])
        {
                int i,j,t;
                for(i=1;i<=5;i++)
                        for(j=i+1;j<=5;j++)
                        {t=c[i][j];
                                c[i][j]=c[j][i];
                                c[j][i]=t;
                        }       

        }     


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter