// 实验一.cpp : 定义控制台应用程序的入口点。///*
1.有长为4的一维整形数组,在主函数中输入数组元素,调用函数计算所有元素的
和并在主函数中输出(分别用数组名和数组元素作为函数参数)
*/
#include "stdafx.h"int add_arrName(int arr[], int length);
int add_arrElement(int a, int b, int c, int d);
intmin(int arr[4][4]);
int main()
{
int arr1[4];
int arr2[4][4];
for (int i = 0; i < 4; i++)
scanf("%d", &arr1[i]);
int sum_arrName = add_arrName(arr1,4);
int sum_arrElement = add_arrElement(arr1[0], arr1[1], arr1[2], arr1[3]);
printf("sum_arrName=%d
sum_arrElement=%d
", sum_arrName, sum_arrElement);
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
scanf("%d", &arr2[i][j]);
int minElement = min(arr2);
printf("minElement=%d
", minElement);
return0;
}
//数组名作为参数int add_arrName(int arr[],int length)
{
int sum = 0;
for (int i = 0; i < length; i++)
{
sum += arr[i];
}
return sum;
}
//数组元素作为参数int add_arrElement(int a,int b, int c, int d)
{
int sum = a+b+c+d;
return sum;
}
/*
2.找出有16个元素的二维整形数组的最小值,并在主函数中输出(用数组名作为函数参数)
*/intmin(int arr[4][4])
{
intmin = arr[0][0];
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
{
if (arr[i][j] < min)
min = arr[i][j];
}
returnmin;
}