level 2
流年亦塵
楼主
//
// main.c
// 自定义赋值
//
// Created by Mac on 16/6/3.
// Copyright © 2016年 Big-Boss. All rights reserved.
//
#include <stdio.h>
/**
* 为传入的二维数组赋值
*
* @param rows 行数
* @param cols 列数
* @param arr 数组名
*/
void setValue(int rows,int cols,int arr[][cols]);
/**
* 打印传入的二维数组的元素
*
* @param rows 行数
* @param cols 列数
* @param arr 数组名
*/
void printArray(int rows,int cols,int arr[][cols]);
int main(int argc, const char * argv[])
{
printf("请输入行数:");
int rows = 0 ;
scanf("%d",&rows);
printf("请输入列数:");
int cols = 0 ;
scanf("%d",&cols);
int arr[rows][cols];
setValue(rows, cols, arr);
printArray(rows, cols, arr);
return 0;
}
void setValue(int rows,int cols,int arr[][cols])
{
for (int i = 0 ;i < rows; i ++)
{
for (int j = 0 ; i < cols; j ++)
{
arr[i][j] = i * j + 10 ;
}
}
}
void printArray(int rows,int cols,int arr[][cols])
{
for (int i = 0 ;i < rows; i ++)
{
for (int j = 0 ; i < cols; j ++)
{
printf("%d",arr[i][j]);
}
printf("/n");
}
}

2016年06月03日 08点06分
1
// main.c
// 自定义赋值
//
// Created by Mac on 16/6/3.
// Copyright © 2016年 Big-Boss. All rights reserved.
//
#include <stdio.h>
/**
* 为传入的二维数组赋值
*
* @param rows 行数
* @param cols 列数
* @param arr 数组名
*/
void setValue(int rows,int cols,int arr[][cols]);
/**
* 打印传入的二维数组的元素
*
* @param rows 行数
* @param cols 列数
* @param arr 数组名
*/
void printArray(int rows,int cols,int arr[][cols]);
int main(int argc, const char * argv[])
{
printf("请输入行数:");
int rows = 0 ;
scanf("%d",&rows);
printf("请输入列数:");
int cols = 0 ;
scanf("%d",&cols);
int arr[rows][cols];
setValue(rows, cols, arr);
printArray(rows, cols, arr);
return 0;
}
void setValue(int rows,int cols,int arr[][cols])
{
for (int i = 0 ;i < rows; i ++)
{
for (int j = 0 ; i < cols; j ++)
{
arr[i][j] = i * j + 10 ;
}
}
}
void printArray(int rows,int cols,int arr[][cols])
{
for (int i = 0 ;i < rows; i ++)
{
for (int j = 0 ; i < cols; j ++)
{
printf("%d",arr[i][j]);
}
printf("/n");
}
}
