(学习路径http://blog.csdn.NET/lanouluanbin/article/details/53518018)
12函数二
#import <Foundation/Foundation.h>
int sumValue(int a,int b);
int sumValue(int a,int b)
{
return a+b;
}
void changeValue(int a,int b);
void changeValue(int a,int b)
{
a = 1000;
b = 2000;
}
//写一个函数 做数组的冒泡排序
void sortArray(int a[],int count);
void sortArray(int a[],int count)
{
for (int i = 0; i<count-1; i++) {
for (int j = 0; j<count-i-1; j++) {
if (a[j]>a[j+1]) {
int temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}
}
}
}
//求两数的最大值
int maxTwoValue(int a,int b);
int maxTwoValue(int a,int b)
{
return a>b?a:b;
}
//求三个数的最大值
int maxThreValue(int a,int b,int c);
int maxThreValue(int a,int b,int c)
{
int max = maxTwoValue(a, b);
return maxTwoValue(max, c);
}
//求四个数的最大值
int maxFourValue(int a,int b,int c,int d);
int maxFourValue(int a,int b,int c,int d)
{
int max = maxThreValue(a, b, c);
return maxTwoValue(max, d);
}
int main(int argc, const char * argv[]) {
int a = 10;
int b = 20;
int result = sumValue(a, b);
printf("%d\n",result);
//形式参数 实际参数
//形参出现在函数的定义时
//实参出现在函数的调用时
int a1 = 10;
int b1 = 20;
changeValue(a1, b1);
printf("%d %d \n",a1,b1);
//数组作为参数,传递的是“地址”
//数组名作为函数的参数 跟其他的不一样 形参实参是同一个值
int array[5] = {11,12,45,23,9};
sortArray(array, 5);
//遍历数组 查看有没有排序成功
for (int i = 0; i<5; i++) {
printf("%d ",array[i]);
}
//函数的嵌套调用 函数中又调用另外一个函数
int a2 = 10;
int b2 = 40;
int c2 = 15;
int d2 = 7;
int result1 = maxFourValue(a2, b2, c2, d2);
printf("四个数的最大值是%d\n",result1);
//函数不允许嵌套定义!!!!!
return 0;
}