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

📄 ok2.cpp

📁 在Unix平台上使用 執行程式檔名為ok2 程式註解檔名為ok2註解 陣列的內容在n.txt裡
💻 CPP
字号:
#include<iostream.h>
#include<fstream.h>
#include <list.h>
#include<stdio.h>
#include<algorithm>
#include<pthread.h>

using namespace std;
void *matrix(void *param);
struct v
{
       int row;
       int r_c;
       int column;
       int txt1[200];
};

int main(int argc,char *argv[])
{
    int q=0,m,n,k;
    int txt[200];
    int sum=0;
    int e=3;
    pthread_t tid;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    string filename;
    cout<<"insert file name:"<<endl;
    cin>>filename;

    ifstream ifile(filename.c_str());

    while(!ifile.eof())
    {
         ifile>>txt[q];
         q++;
    }
    m=txt[0];
    n=txt[1];
    k=txt[2];
    
    struct v *data = (struct v *) malloc(sizeof(struct v));
    data->row = m;
    data->r_c = n;
    data->column = k;
    data->txt1=txt;
    pthread_create(&tid, &attr, matrix, data);
    pthread_join(tid, NULL)
    system("pause");
    return 0;
}

void *matrix(void *param)
{
     int a[m][n],b[n][k];  
     int q=0,m,n,k;
     int txt[200];
     int sum=0;
     int e=3;

    struct v *temp = (v*)param;

    m = temp->row;
    n = temp->r_c;
    k = temp->column;
    txt=temp->txt1;
 
    for(int i=0;i<m;i++)
    {
         for(int j=0;j<n;j++)
         {
              a[i][j]=txt[e];
              e++;        
         }     
    }

    for(int i=0;i<n;i++)
    {
         for(int j=0;j<k;j++)
         {
              b[i][j]=txt[e];
              e++;  
              
         }
         
    }

    cout<<"A="<<endl;
    for(int i=0;i<m;i++)
    {
         for(int j=0;j<n;j++)
         {
              cout<< '\t'<<"["<<a[i][j]<<"]"; 
         }
         cout<<endl;
    }
    cout<<"========================================"<<endl;
    cout<<"B="<<endl;
    
    for(int i=0;i<n;i++)
    {
         for(int j=0;j<k;j++)
         {

              cout<< '\t'<<"["<<b[i][j]<<"]";

              
         }
         
         cout<<endl;
         
    }
    cout<<"========================================"<<endl;
    cout<<"C="<<endl;
    

    for(int i=0;i<m;i++)
    {

         for(int j=0;j<k;j++)
         {
              sum=0;
              for(int l=0;l<n;l++)
              {
                   sum+=a[i][l]*b[l][j];
              }
              cout<< '\t'<<"["<<sum<<"]";
         }
         cout<<endl;
    }
  
    pthread_exit(0);
}

⌨️ 快捷键说明

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