⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.cpp

📁 自己写的矩阵压缩算法的c语言描述
💻 CPP
字号:
// 这是使用应用程序向导生成的 VC++ 
// 应用程序项目的主项目文件。

#include "stdafx.h"
#include "stdio.h"
#using <mscorlib.dll>

using namespace System;
#define OK 1
#define FALSE 0
#define ERROR 0
#define TRUE 1
typedef int ElemType;
typedef ElemType Status;

//下标转换函数,将2维下标转换为1维
Status ij_To_k( ElemType i,ElemType j )
{
	if(i<1||j<1)
		return ERROR;
	if(i>=j)
		return ((i-1)*i/2+j-1);
	else
		return ((j-1)*j/2+i-1);
}

//特殊矩阵的输入
Status Input(ElemType A[],int n)
{
	int k; 
	for(k=0;k<(n+1)*n/2;k++)
		scanf("%d",&A[k]);
	return OK;
}

//读取对称矩阵中的某个元素
Status GetElem(ElemType A[],int i,int j,ElemType &e)
{
	int k = ij_To_k(i,j);
	if(k>=0)
	{
		e=A[k];
		return OK;
	}
	else
		return ERROR;
}

//修改对称矩阵中某个元素
Status Change(ElemType A[],int i,int j,ElemType e)
{
	int k = ij_To_k(i,j);
	if(k>=0)
	{
		A[k] = e;
		return OK;
	}
	else
		return ERROR;
}

//打印对称矩阵
void Print(ElemType A[],int n)
{
	int e;
	for(int i=1;i<=n;i++)
		printf("\n");
	for(int j=1;j<=n;j++)
	{
		GetElem(A,i,j,e);
		printf("%3d",e);
	}
}
int _tmain()
{
    static int A[25];
	Input(A,5);
	Print(A,25);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -