成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

c語言矩陣求轉(zhuǎn)置數(shù)組函數(shù),求矩陣轉(zhuǎn)置的程序C語言

c語言矩陣轉(zhuǎn)置函數(shù),定義一個二維數(shù)組 int a[5][3],保存一個5*3的矩陣a,求他的轉(zhuǎn)置矩陣b。

/* 程式功能: 矩陣轉(zhuǎn)置 (transportation) *//*輸入:m×n矩陣A *//*輸出:矩陣B,B=AT */#include void main() { int i, j, m=5, n=5; int B[6][6], A[6][6]; printf("請依序輸入二維陣列A(5x5)的元素內(nèi)容(可以5個一行,可以空格或回車隔開): \n"); for (i = 1; i = 5; i++) { for (j = 1; j = 5; j++) { scanf("%d", A[i][j]); } } printf("\n\n原始:\n"); for(i = 1; i = m; i ++) { for(j = 1; j =n; j++) { printf("%4d",A[i][j]); } printf("\n"); } printf("\n轉(zhuǎn)置後:\n"); for (i = 1; i = m; i++) { for (j = 1; j = n; j++) { B[i][j] = A[j][i]; /*作轉(zhuǎn)置的動作*/ printf("%4d ", B[i][j]); /*輸出轉(zhuǎn)置後的結(jié)果*/ } printf("\n"); }}

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、小程序設(shè)計、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了霍城免費(fèi)建站歡迎大家使用!

C語言-矩陣轉(zhuǎn)置

①目標(biāo)

將一個二維數(shù)組表示的矩陣轉(zhuǎn)置

②命令行

#includestdio.h

#include stdlib.h

~

③定義函數(shù)

void fun(int array[3][3])

{int i,j,t;

for(i=0;i<3;i++)

for(j=i+1;j<3;j++)

/*注意:只遍歷了矩陣的右上半部分。

如果for(j=0;j<3;j++,表示遍歷矩陣全部元素,右上與左下交換,左下又與右上交換,導(dǎo)致重復(fù)轉(zhuǎn)置,矩陣沒有變化。*/

{t=array[i][j];

array[i][j]=array[j][i];

array[j][i]=t;}

/*交換語句,矩陣右上半部分,與對應(yīng)左下半部分,元素交換,完成轉(zhuǎn)置*/

}

~

④主函數(shù)(調(diào)用)

void main()

{int i,j;

int array[3][3]={{1,2,3},{4,5,6},{7,8,9}};

for(i=0;i<3;i++)

{for(j=0;j<3;j++)

/*輸出原矩陣,遍歷全部*/

printf("%7d",array[i][j]);

printf("\n");}

fun(array);

/*利用fun函數(shù)完成轉(zhuǎn)置*/

printf("converted array:\n");

for(i=0;i<3;i++)

{for(j=0;j<3;j++)

printf("%7d",array[i][j]);

printf("\n");}

}

用C語言編寫一個矩陣轉(zhuǎn)置的函數(shù),矩陣的行數(shù)和列數(shù)在程序中由用戶輸入,請問怎么寫,非常感謝

我的代碼邏輯是:

矩陣行指針初值指向每行首地址,迭代依次取所有行指針指向值組成新行,所有行指針自增。最終組合新的矩陣。

#include?stdio.h

#include?malloc.h

int?**getList(int?row,int?clo);//獲取矩陣地址空間

void?setNum(int?**nList,int?n);//填寫數(shù)值

void?prtList(int?**nList,int?row,int?clo);//打印矩陣

int?**zz(int?**nList,int?row,int?clo);//轉(zhuǎn)置函數(shù)

int?main()

{

int?row,clo,**nList=NULL,**nListSave=NULL;

printf("輸入矩陣行列數(shù):");

scanf("%d%d",row,clo);

nList=getList(row,clo);

setNum(nList,row*clo);

printf("輸入的矩陣為:\n");

prtList(nList,row,clo);

printf("轉(zhuǎn)置后的矩陣為:\n");

nListSave=zz(nList,row,clo);

free(nList);

nList=nListSave;

prtList(nList,clo,row);

return?0;

}

int?**zz(int?**nList,int?row,int?clo)

{

int?*nSave=NULL,**listSave=NULL,**listp=nList,*p=NULL,i,j;

nSave=(int?*)malloc(sizeof(int)*row*clo);

listSave=(int?**)malloc(sizeof(int*)*clo);//倒置后的矩陣

p=nSave;

for(j=0;jclo;j++)

{

for(i=0;irow;i++)

{

*p++=*listp[i];

listp[i]=listp[i]+1;

}

}

for(i=0;iclo;i++)

listSave[i]=nSave[i*row];

for(i=0;irow;i++)

free(nList[i]);//釋放原矩陣行空間

return??listSave;

}

void?prtList(int?**nList,int?row,int?clo)

{

int?i,j;

for(i=0;irow;i++)

{

for(j=0;jclo;j++)

printf("%d?",nList[i][j]);

printf("\n");

}

}

void?setNum(int?**nList,int?n)

{

int?*p=nList[0];

printf("填寫矩陣中%d個數(shù)值:\n",n);

while(n--0)

scanf("%d",p++);

}

int?**getList(int?row,int?clo)

{

int?*nums,**nList,i;

nums=(int?*)malloc(sizeof(int)*row*clo);

nList=(int?**)malloc(sizeof(int*)*row);

for(i=0;irow;i++)

nList[i]=nums[i*clo];

return?nList;

}

文章名稱:c語言矩陣求轉(zhuǎn)置數(shù)組函數(shù),求矩陣轉(zhuǎn)置的程序C語言
網(wǎng)頁路徑:http://jinyejixie.com/article48/hsodhp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站建設(shè)定制開發(fā)、網(wǎng)站收錄外貿(mào)建站、網(wǎng)站導(dǎo)航、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計
呼图壁县| 广宁县| 沙湾县| 刚察县| 乌鲁木齐县| 石林| 临西县| 永州市| 改则县| 汝州市| 涪陵区| 游戏| 洛阳市| 根河市| 根河市| 赞皇县| 通道| 延安市| 永福县| 霍林郭勒市| 临清市| 龙门县| 红原县| 清流县| 长宁区| 北票市| 丹巴县| 木兰县| 剑河县| 溧水县| 绵竹市| 乌鲁木齐县| 本溪市| 南阳市| 雅江县| 富民县| 双柏县| 遵义县| 清新县| 克山县| 平山县|