C語言實現矩陣翻轉(上下翻轉、左右翻轉)
來源:本站原創(chuàng)|時間:2020-01-10|欄目:C語言|點擊: 次
C語言實現矩陣翻轉 上下翻轉與左右翻轉
實例代碼:
#include <stdio.h> void matrix (int m, int n, int t) { int arr[m][n]; int i, j, k; for (i = 0; i < m; i++){ for (j = 0; j < n; j++){ scanf("%d", &arr[i][j]); } } if (t == 0){//左右翻轉 for (i = 0; i < m; i++){ for (j = n-1; j >= 0; j--){ if ( j == 0 ) { printf("%d", arr[i][j]); } else { printf("%d ", arr[i][j]); } } printf("\n"); } } else if (t == 1){//上下翻轉 for (i = m-1; i >= 0; i--){ for (j = 0; j < n; j++){ if ( j == n - 1 ) { printf("%d", arr[i][j]); } else { printf("%d ", arr[i][j]); } } printf("\n"); } } } int main() { int m, n, t; scanf("%d %d %d", &m, &n, &t); matrix (m, n, t); return 0; }
動態(tài)分配內存
void matrix (int m, int n, int t) { int i, j; int **arr=(int**)malloc(m*sizeof(int*)); for(i = 0; i < m; i++) { arr[i] = (int*)malloc(n * sizeof(int)); for(j = 0; j < n;j++) { scanf("%d", &arr[i][j]); } } /* int **arr = new int*[m]; for(i=0;i<m;i++) { arr[i] = new int[n]; for(j=0;j<n;j++) { scanf("%d", &arr[i][j]); } } */ if (t == 0){//左右翻轉 for (i = 0; i < m; i++){ for (j = n-1; j >= 0; j--){ if ( j == 0 ) { printf("%d", arr[i][j]); } else { printf("%d ", arr[i][j]); } } printf("\n"); } } else if (t == 1){//上下翻轉 for (i = m-1; i >= 0; i--){ for (j = 0; j < n; j++){ if ( j == n - 1 ) { printf("%d", arr[i][j]); } else { printf("%d ", arr[i][j]); } } printf("\n"); } } }
感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
上一篇:詳談C++的內存泄漏問題
欄 目:C語言
下一篇:C++的虛析構詳解及實例代碼
本文標題:C語言實現矩陣翻轉(上下翻轉、左右翻轉)
本文地址:http://mengdiqiu.com.cn/a1/Cyuyan/1564.html
您可能感興趣的文章
- 04-02c語言函數調用后清空內存 c語言調用函數刪除字符
- 04-02c語言的正則匹配函數 c語言正則表達式函數庫
- 04-02func函數+在C語言 func函數在c語言中
- 04-02c語言中對數函數的表達式 c語言中對數怎么表達
- 04-02c語言用函數寫分段 用c語言表示分段函數
- 04-02c語言編寫函數冒泡排序 c語言冒泡排序法函數
- 04-02c語言沒有round函數 round c語言
- 04-02c語言分段函數怎么求 用c語言求分段函數
- 04-02C語言中怎么打出三角函數 c語言中怎么打出三角函數的值
- 04-02c語言調用函數求fibo C語言調用函數求階乘


閱讀排行
本欄相關
- 04-02c語言函數調用后清空內存 c語言調用
- 04-02func函數+在C語言 func函數在c語言中
- 04-02c語言的正則匹配函數 c語言正則表達
- 04-02c語言用函數寫分段 用c語言表示分段
- 04-02c語言中對數函數的表達式 c語言中對
- 04-02c語言編寫函數冒泡排序 c語言冒泡排
- 04-02c語言沒有round函數 round c語言
- 04-02c語言分段函數怎么求 用c語言求分段
- 04-02C語言中怎么打出三角函數 c語言中怎
- 04-02c語言調用函數求fibo C語言調用函數求
隨機閱讀
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 01-10SublimeText編譯C開發(fā)環(huán)境設置
- 04-02jquery與jsp,用jquery
- 01-10delphi制作wav文件的方法
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-11ajax實現頁面的局部加載
- 01-10C#中split用法實例總結
- 08-05dedecms(織夢)副欄目數量限制代碼修改
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 08-05DEDE織夢data目錄下的sessions文件夾有什