蓝鸥iOS从零基础到精通就业-C语言入门 12函数二

蓝鸥iOS从零基础到精通就业-C语言入门

 (学习路径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;
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值