Exemple #1
0
void main( )
{
    struct sparse s[5] ;
    int i ;

    clrscr( ) ;

    for ( i = 0 ; i <= 4 ; i++ )
    	initsparse ( &s[i] ) ;

	create_array ( &s[0] ) ;

	create_tuple ( &s[1], s[0] ) ;
	display_tuple ( s[1] ) ;

	create_array ( &s[2] ) ;

	create_tuple ( &s[3], s[2] ) ;
	display_tuple ( s[3] ) ;

	addmat ( &s[4], s[1], s[3] ) ;

	printf ( "\nResult of addition of two matrices: " ) ;
	display_result ( s[4] ) ;

    for ( i = 0 ; i <= 4 ; i++ )
		delsparse ( &s[i] ) ;

    getch( ) ;
}
Exemple #2
0
int main( )
{
	struct sparse s[5] ;
	int i ;

	system ( "cls" ) ;

	for ( i = 0 ; i <= 4 ; i++ )
		initsparse ( &s[i] ) ;

	create_array ( &s[0] ) ;

	create_tuple ( &s[1], s[0] ) ;
	display_tuple ( s[1] ) ;

	create_array ( &s[2] ) ;

	create_tuple ( &s[3], s[2] ) ;
	display_tuple ( s[3] ) ;

	addmat ( &s[4], s[1], s[3] ) ;

	printf ( "Result of addition of two matrices:" ) ;
	display_result ( s[4] ) ;

	for ( i = 0 ; i <= 4 ; i++ )
		delsparse ( &s[i] ) ;

	return 0 ;
}
int main()
{
	printf("**********************************************************\n");
	printf("                     稀疏矩阵运算器                       \n");
	printf("**********************************************************\n");
	int a=-1;
	while(a)
	{
	printf("功能列表\n\n");
	printf("1.两个矩阵相加\n");
	printf("2.两个矩阵相减\n");
	printf("3.两个矩阵相乘\n\n");
	printf("输入0退出程序\n\n");
	printf("请输入你想使用功能对应的数字:");
	int a,b,c,d;
	scanf("%d",&a);
	if(a==1)
		{
			mat x,y,z;
			printf("请输入第一个矩阵的行数和列数(不超过20):");
			scanf("%d %d",&x.mu,&x.nu);
			printf("请输入第二个矩阵的行数和列数(不超过20):");
			scanf("%d %d",&y.mu,&y.nu);
			if(x.nu!=y.nu||x.mu!=y.mu)printf("两个矩阵不匹配,无法相加\n\n");
			else	addmat(x,y,z);
		}//a==1
	else if(a==2)
		{
			mat x,y,z;
			printf("请输入第一个矩阵的行数和列数(不超过20):");
			scanf("%d %d",&x.mu,&x.nu);
			printf("请输入第二个矩阵的行数和列数(不超过20):");
			scanf("%d %d",&y.mu,&y.nu);
			if(x.nu!=y.nu||x.mu!=y.mu)printf("两个矩阵不匹配,无法相减\n\n");
			else	subtmat(x,y,z);
		}//a==2
	else if(a==3)
		{
			mat x,y,z;
			printf("请输入第一个矩阵的行数和列数(不超过20):");
			scanf("%d %d",&x.mu,&x.nu);
			printf("请输入第二个矩阵的行数和列数(不超过20):");
			scanf("%d %d",&y.mu,&y.nu);
			if(x.nu!=y.mu)printf("两个矩阵不匹配,无法相乘\n\n");
			else	multmat(x,y,z);
		}//a==3
	else if(a==0)break;
	}//while
	return 0;
}
Exemple #4
0
int main() {
    int dim = 3;
    int A[][N] = {1,2,3,4,5,6,7,8,9}; // Matrix A
    int B[][N] = {9,8,7,6,5,4,3,2,1}; // Matrix B
    int C[N][N];

    addmat(dim, A, B, C);

    for (int i = 0; i < dim; i ++) {
        for (int j = 0; j < N; j++) {
            printf("%d ", C[i][j]);
        }
        printf("\n");
    }
    return 0;
}