欧美色欧美亚洲高清在线观看,国产特黄特色a级在线视频,国产一区视频一区欧美,亚洲成a 人在线观看中文

  1. <ul id="fwlom"></ul>

    <object id="fwlom"></object>

    <span id="fwlom"></span><dfn id="fwlom"></dfn>

      <object id="fwlom"></object>

      C課程設計矩陣的加減乘混合運算

      時間:2019-05-12 02:06:55下載本文作者:會員上傳
      簡介:寫寫幫文庫小編為你整理了多篇相關(guān)的《C課程設計矩陣的加減乘混合運算》,但愿對你工作學習有幫助,當然你在寫寫幫文庫還可以找到更多《C課程設計矩陣的加減乘混合運算》。

      第一篇:C課程設計矩陣的加減乘混合運算

      矩陣混合運算

      指導教師:

      浙江理工大學

      班級:

      學號:

      姓名:

      矩陣混合運算 目 錄

      一、程序要求

      二、輸入輸出范例

      三、程序結(jié)構(gòu)分析及關(guān)鍵函數(shù)說明

      四、程序代碼與說明

      五、運行結(jié)果與分析

      六、設計日志及心得體會

      一、程序要求及范例

      ·定義矩陣(維數(shù)小于5×5)的加減法和乘法 ·計算輸入的若干矩陣的加減法運算和乘法混合運算

      ·矩陣數(shù)目不定,混合運算順序不定,矩陣數(shù)值不定,均有鍵盤輸入控制

      ·若輸入有錯,可以隨時更改任一矩陣數(shù)值

      ·當輸入矩陣不能滿足矩陣運算時,提示矩陣維數(shù)錯誤

      二、輸入輸出范例

      ·輸入:

      -首先輸入每個矩陣的數(shù)值,輸入矩陣格式如[1 1 1;2 2 2]-輸入幾個矩陣的混合運算 ·輸出:

      -輸出計算結(jié)果

      ·輸入范例: A=[1 1 1;2 2 2] B=[1 0;0 1;1 1] C=[1 0;0 1] D=C+A*B或者D=A*B+C ·輸出b->data[i][j];

      }

      }

      return 1;

      } }

      3.乘運算函數(shù)

      該程序設計的核心問題是矩陣的乘法運算的邏輯性的編寫,在進行矩陣相乘前要判斷兩矩陣是否能夠相乘,即判斷內(nèi)積是否相等,如果能就按照矩陣的相乘方式進行運算,若不能則提示錯誤并返回,具體的程序段如下:

      int multiplyMatrix(Matrix *c, Matrix *a, Matrix *b){

      int i, j, k;

      if(a->cols!= b->rows){ printf(“矩陣維數(shù)輸入錯誤!”);

      return 0;

      }

      else

      {

      c->rows = a->rows;

      c->cols = b->cols;

      for(i = 0;i < c->rows;i++)

      {

      for(j = 0;j < c->cols;j++)

      {

      c->data[i][j] = 0;

      for(k = 0;k < a->cols;k++)

      {

      c->data[i][j] += a->data[i][k]*b->data[k][j];

      }

      }

      }

      return 1;

      } }

      四、程序代碼與說明

      #include #include #include #include #define MAX_DIM 6 #define MAX_CHAR 128 typedef struct //結(jié)構(gòu)體定義矩陣 { float data[MAX_DIM][MAX_DIM];//二維數(shù)組表示矩陣 int rows;//行 int cols;//列 } Matrix;typedef struct _ListNode //定義一個頭結(jié)點 { char name[MAX_CHAR];Matrix *mat;struct _ListNode *next;//指向下一個結(jié)點 } ListNode;

      typedef struct { ListNode *head;//定義一個指向頭結(jié)點的指針 } MList;enum TYPE {OP, MAT};//枚舉類型

      typedef struct _Token //定義Token標識符 判斷表達式 { union //聯(lián)合體 取值為 op 和 mat中結(jié)構(gòu)最大的值 { char op;Matrix *mat;};enum TYPE type;//聯(lián)合體的類型 } Token;typedef struct _Stack //定義棧 { Token **arr;//用數(shù)組存儲標識符 int n;//數(shù)組里標識符的個數(shù) int cap;//數(shù)組的大小 } Stack;

      Stack* initStack(int cap);//初始化,定義一個空棧 void freeStack(Stack *pStack);//釋放棧的空間

      void reszieStack(Stack *pStack, int newCap);//重定義棧的大小 void push(Stack *pStack, Token *pToken);//入棧操作 Token* pop(Stack *pStack);//出棧 Token* top(Stack *pStack);//棧頂

      int getIndex(char ch);//不同標識符對應不同的操作 char priorMap[9][9] = { {'>', '>', '<', '<', '<', '<', '<', '>', '>'}, {'>', '>', '<', '<', '<', '<', '<', '>', '>'}, {'>', '>', '>', '>', '<', '<', '<', '>', '>'}, {'>', '>', '>', '>', '<', '<', '<', '>', '>'}, {'>', '>', '>', '>', '>', '>', '<', '>', '>'}, {'>', '>', '>', '>', '>', '>', '<', '>', '>'}, {'<', '<', '<', '<', '<', '<', '<', '=', '$'}, {'>', '>', '>', '>', '>', '>', '&', '>', '>'}, {'<', '<', '<', '<', '<', '<', '<', '&', '='} };Matrix *newMatrix(int rows, int cols);//函數(shù)原型,創(chuàng)建新矩陣 void freeMatrix(Matrix *mat);//銷毀矩陣,釋放內(nèi)存

      int addMatrix(Matrix *c, Matrix *a, Matrix *b);//矩陣的加法

      int subtractMatrix(Matrix *c, Matrix *a, Matrix *b);//矩陣的減法 int multiplyMatrix(Matrix *c, Matrix *a, Matrix *b);//矩陣的乘法 void printMatrix(Matrix *mat);//輸出結(jié)果 ListNode *newNode(char name[], Matrix *mat);MList *newMList();void freeNode(ListNode *node);void freeMList(MList *ml);void addNode(MList *ml, ListNode *node);ListNode *parseMat(char line[]);void printLNode(ListNode *node);Matrix *findByName(MList *ml, char name[]);int main(){ printf(“矩陣的混合運算n”);

      2]n“);

      char line[MAX_CHAR];char name[MAX_CHAR];char *pch;MList *ml = newMList();Matrix *newMat = NULL;

      printf(”矩陣范例A=[1 1 1;2 2 printf(“請按范例格式輸入n”);

      while(1){ fgets(line, MAX_CHAR, stdin);//輸入一串字符 if(strlen(line)== 1 && line[0] == 'n'){ continue;} pch = strchr(line, '[');if(pch!= NULL){ ListNode *node = parseMat(line);addNode(ml, node);} else { pch = strchr(line, '=');*pch = '