weixin_74390886 2022-12-11 22:14 采纳率: 71.4%
浏览 8

为什么z函数出错,变量欠缺;

#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <cstdlib>
#include <string.h>
#define maxsize 100
#define m 2
#define n 3
typedef int    elemtype;
typedef struct{
    int i,j;
    elemtype e;
}Triple;
typedef struct{
    Triple date[maxsize+1];
    int mu,nu,tu;
}TSMatrix;
void change(TSMatrix &t,elemtype a[m][n]){
    int k=1;
    t.mu=m;
    t.nu=n;
    t.tu=0;
    for(int e=0;e<m;e++){
        for(int s=0;s<n;s++)
            if(a[e][s]!=0)
            {
                t.date[k].i=e;
                t.date[k].j=s;
                t.date[k].e=a[e][s];
                t.tu++;
                k++;
            }
    }
}
void DipMat(TSMatrix t){
    cout<<"行号"<<" "<<"列号"<<" "<<"值\n";
    for(int k=0;k<t.tu;k++){
        cout<<t.date[k].i+1<<" "<<t.date[k].j+1<<" "<<t.date[k].e<<"\n";
    }
}
void DipMatjz(TSMatrix t){
    int x=1,a[n][m],s,y;
    for(y=0;y<t.mu;y++)
    for(s=0;s<t.nu;s++)
        if(t.date[x].i==y&&t.date[x].j==s)
            a[y][s]=t.date[x].e;
        else
            a[y][s]=0;
        for(y=0;y<t.mu;y++){
    for(s=0;s<t.nu;s++)
        cout<<a[y][s]<<" ";
    cout<<"\n";
        }
}
 
void z(TSMatrix m,TSMatrix &T){
    int num[n+1],cpot[maxsize],col=1,x;
    T.mu=m.nu;
    T.nu=m.mu;
    T.tu=m.tu;
    if(T.tu){
        for(col=1;col<=m.nu;++col)
            num[col]=0;
        for(x=1;T<=m.tu;T++)
            ++num[m.date[x].j];
        cpot[1]=1;
        for(col=2;col<=m.nu;++col)
            cpot[col]=cpot[col-1]+num[col-1];
        for(x=1;x<=t.tu;x++){
            col=m.date[x].j;
            y=copt[col];
            T.date[y].i=m.date[x].j;
            T.date[y].i=m.date[x].j;
            T.date[y].e=m.date[x].e;
            copt[col]++;
        }
    }
}
void main(){
    cout<<"请输入"<<m<<"行"<<n<<"列矩阵:\n";
    elemtype a[m][n];TSMatrix t,p;
    for(int e=0;e<m;e++)
    for(int s=0;s<n;s++)
        cin>>a[e][s];
    change(t,a);
    DipMat(t);
    z(t,p);
    cout<<"转置后矩阵为:\n";
    DipMatjz(p);
}

  • 写回答

1条回答 默认 最新

  • ShowMeAI 2022-12-11 23:06
    关注

    详细解答如下,望采纳


    这段代码中的z函数缺少一个重要的变量:行数。可以在z函数的参数列表中添加一个行数变量,并在函数内部使用它。例如:

    void z(TSMatrix m, int row, TSMatrix &T){
    // 在这里使用row变量
    }
    

    在调用z函数时,您需要提供矩阵的行数,例如:

    z(t, m, p);
    
    评论

报告相同问题?

问题事件

  • 创建了问题 12月11日

悬赏问题

  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
  • ¥15 数字信号处理考试111
  • ¥100 关于#audobe audition#的问题,如何解决?
  • ¥15 allegro17.2生成bom表是空白的
  • ¥15 请问一下怎么打通CAN通讯
  • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
  • ¥35 navicat将excel中的数据导入mysql出错
  • ¥15 rt-thread线程切换的问题
  • ¥15 高通uboot 打印ubi init err 22