求m阶矩阵的n次幂


题目如题

直接上代码了。

 1 import java.util.Scanner;
 2 
 3 public class test
 4 {
 5     public static void main(String [] args)
 6     {
 7         int m,n,i,j,p;
 8         int array[][]=new int[100][100];
 9         int temp[][]=new int[100][100];
10         Scanner scanner=new Scanner(System.in);
11         System.out.printf("input m,n:");   //m表示矩阵的阶数,n表示的幂数
12         m=scanner.nextInt();
13         n=scanner.nextInt();
14         System.out.printf("input the value of matrix \n");
15         for(i=0;i<m;i++)    //输入矩阵
16         {
17             for(j=0;j<m;j++)
18             {
19                 array[i][j]=scanner.nextInt();
20             }
21         }
22         for(i=0;i<m;i++)
23         {
24             for(j=0;j<m;j++)
25             {
26                for(p=0;p<m;p++)
27                 temp[i][j]+=array[i][p]*array[p][j];
28             }
29         }
30         
31         System.out.printf("the mth power of matrix:\n");
32         for(i=0;i<m;i++)  //输出结果
33         {
34             for(j=0;j<m;j++)
35             {
36                 System.out.printf("%3d",temp[i][j]);
37             }
38             System.out.printf("\n");
39         }
40     }
41 }

 

不解释。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM