A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© muyan091115 中级黑马   /  2016-5-21 23:27  /  660 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. //
  2. //  main.c
  3. //  Test_01
  4. //
  5. //  Created by 蒋伟 on 16/5/14.
  6. //  Copyright (c) 2016年 蒋伟. All rights reserved.
  7. //

  8. #include <stdio.h>

  9. /**
  10. *  为二维数组按特定规则赋值
  11. *
  12. *  @param rows 行数
  13. *  @param cols 列数
  14. *  @param arr  目标数组
  15. */
  16. void fuZhi(int rows, int cols, int arr[rows][cols]);

  17. /**
  18. *  打印二维数组元素
  19. *
  20. *  @param rows 行数
  21. *  @param cols 列数
  22. *  @param arr  目标数组
  23. */
  24. void printfArr(int rows, int cols, int arr[rows][cols]);

  25. int main(int argc, const char * argv[]) {
  26.     printf("请输入二位数组的行数和列数:");
  27.     int rows, cols;
  28.     scanf("%d%d",&rows,&cols);
  29.     int arr[rows][cols];
  30.     fuZhi(rows,cols,arr);
  31.     printfArr(rows,cols,arr);
  32.     return 0;
  33. }

  34. /**
  35. *  为二维数组按特定规则赋值
  36. *
  37. *  @param rows 行数
  38. *  @param cols 列数
  39. *  @param arr  目标数组
  40. */
  41. void fuZhi(int rows, int cols, int arr[rows][cols]){
  42.     for(int i = 0; i < rows; i++){
  43.         for(int j = 0; j < cols; j++){
  44.             arr[i][j] = i * j + 10;
  45.         }
  46.     }
  47. }

  48. /**
  49. *  打印二维数组元素
  50. *
  51. *  @param rows 行数
  52. *  @param cols 列数
  53. *  @param arr  目标数组
  54. */
  55. void printfArr(int rows, int cols, int arr[rows][cols]){
  56.     for(int i = 0; i < rows; i++){
  57.         for(int j = 0; j < cols; j++){
  58.             printf("%d\t",arr[i][j]);
  59.         }
  60.         printf("\n");
  61.     }
  62. }






复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马