《C语言实现的矩阵加减乘法运算系统.doc》由会员分享,可在线阅读,更多相关《C语言实现的矩阵加减乘法运算系统.doc(25页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Four short words sum up what has lifted most successful individuals above the crowd: a little bit more.-author-dateC语言实现的矩阵加减乘法运算系统C语言实现的矩阵加减乘法运算系统/*本矩阵运算系统可以完成矩阵的加、减、乘法,但是只限于方阵*/#include<stdio.h>#include<math.h>/*-全局变量定义-*/int n,m,c=0;int a100100,b100100;int fc100100;/*-函数声明-*/void prin
2、t();void print_sub();void input_marry();void add_marry();void sub_marry();void mut_marry();/*-主函数-*/void main()print();scanf("%d",&c);while(c!='0')if(c=1) input_marry();if(c=2) add_marry();if(c=3) sub_marry();if(c=4) mut_marry();if(c=0) c='0'printf("请选择运算:nn")
3、;scanf("%d",&c);/*-打印函数-*/void print()printf(" 矩阵运算管理系统 n");printf("-n");printf("1 输入矩阵n");printf("2 矩阵相加n");printf("3 矩阵相减n");printf("4 矩阵相乘n");printf("0 退出系统n");printf("-n");printf("请选择:nn");/*-
4、矩阵输入-*/void input_marry()int i,j;printf("请输入矩阵的维数nn");scanf("%d",&n);m=n*n;/*-第一个矩阵输入-*/printf("请输入第一个矩阵a(共有%4d个元素):nn",m);dom-;for(i=0;i<n;i+)for(j=0;j<n;j+)scanf("%d",&aij);while(m<0);/*-打印第一个矩阵-*/printf("您输入的矩阵a=nn");for(i=0;i<
5、n;i+)for(j=0;j<n;j+)printf("%10d",aij);if(j=n-1)printf("n");/*-第二个矩阵输入-*/m=n*n;printf("请输入第二个矩阵b(共有%4d个元素):nn",m);dom-;for(i=0;i<n;i+)for(j=0;j<n;j+)scanf("%d",&bij);while(m<0);/*-打印第二个矩阵-*/printf("您输入的矩阵b=nn");for(i=0;i<n;i+)for(j
6、=0;j<n;j+)printf("%10d",bij);if(j=n-1)printf("n");print_sub();/*-矩阵加法运算-*/void add_marry()int i,j;for(i=0;i<n;i+)for(j=0;j<n;j+) fcij=0;fcij=aij+bij;printf("矩阵和为:nn");for(i=0;i<n;i+)for(j=0;j<n;j+)printf("%10d",fcij);if(j=n-1)printf("n"
7、;);print_sub();/*-矩阵减法运算-*/void sub_marry()int i,j;for(i=0;i<n;i+)for(j=0;j<n;j+) fcij=0;fcij=aij-bij;printf("矩阵差为:nn");for(i=0;i<n;i+)for(j=0;j<n;j+)printf("%10d",fcij);if(j=n-1)printf("n");print_sub();/*-矩阵乘法运算-*/void mut_marry()int k,i,j;for (i=0;i<n;i
8、+)for (j=0;j<n;j+) fcij=0;for (k=0;k<n;k+)fcij+=aik*bkj;printf("矩阵积为:nn");for(i=0;i<n;i+)for(j=0;j<n;j+)printf("%10d",fcij);if(j=n-1)printf("n");print_sub(); /*-子打印函数-*/void print_sub()printf("n-n");printf("n2 矩阵相加;3 矩阵相减;4 矩阵相乘;0 退出系统n");printf("n-n");-