iOS C语言6_函数

//

//  main.m

//  C6_函数

//

//  Created by dllo on 15/7/6.

//  Copyright (c) 2015 zhozhicheng. All rights reserved.

//


#import <Foundation/Foundation.h>


// 函数的定义

// 函数的形式:1无返回值无参数

// 买菜的功能

没有返回值,void

// 第二部分:函数名,起名原则和变量名是一样的

// 第三部分:参数

//void buyVegetable(){

//    printf("100块钱都不给我,怎么买菜\n");

//    int a = 10;

//    a += 20;

//}

//

//

2:有返回值,但没有参数

//int buyVegetableTwo(){

//    printf("老板没给我钱,我还挣了一百\n");

//    // return下的代码不会被执行

//    return 80;

//    printf("nihao");

//    

//}

//

3.没有返回值,有参数

//void addNum(int a,int b){

//    printf("%d\n",a+b );

//}


// 4.有返回值,而且有参数

//int addTwoNum(int a,int b){

//    return a + b;

//    

//}

//

//int maxInThree(int a,int b, int c ){

//    a = a > b ? a : b;

//    c = a > c ? a : c;

//    return c;

//   }



编写函数sumValue(int n):计算1->n的和

// int sumValue(int n){

//     int sum=0;

//     for (int i=1; i<=n ; i++) {

//        sum = sum+i;

//         

//     }return sum;

//    

//    

//}

//int dayOfYear(year,month,day){

//    switch (month-1) {

//        case 11:

//            day += 30;

//        case 10:

//            day += 31;

//        case 9:

//            day += 30;

//        case 8:

//            day += 31;

//        case 7:

//            day += 31;

//        case 6:

//            day += 30;

//        case 5:

//            day += 31;

//        case 4:

//            day += 30;

//        case 3:

//            day += 31;

//        case 2:

//            day += 28;

//        case 1:

//            day += 31;

//

//        break;

//            

//        default:

//            break;

//    }

//    if (year % 400 == 0 || (year % 4 == 0 && year % 100 !=0)) {

//        if (month > 2) {

//            day = day + 1;

//        }

//    }return day;


返回三个函数中间数

//int middleNum(int a,int b ,int c){

//    // 找出最大最小,最后通过求和把最大最小减去,就是中间数

//    int max= a > b ? a : b;

//    max =max > c ? max : c ;

//    int min= a < b ? a : b;

//    min =min  < c ? min  : c ;

//    int mid = a + b + c - max -min;

//

//}printf("%d",mid);



//  // 计算几位数

//int number(int n){

用来保存多少位

//    int count = 0;

//    while (n != 0) {

//        n = n / 10;

//        count++;

//    }return count;

//    

//    

//}



















int main(int argc, const char * argv[]){


//  // 通过函数的调用,来使用这个功能的函数

//    buyVegetable();

//    

//    //

//    int result = buyVegetableTwo();

//    printf("%d\n",result);

//    int a=20,b=30;

//    //a,b是实参,他们是实实在在存在在主函数里的函数,形参是用来接受调用的时候传过去的内容的容器,作用范围就在容器里

//    addNum(b,a);

//    //传参数的事后要注意形参的类型和顺序

//

    

//    

//    int result = maxInThree(20, 15, 3);

//     printf("%d",result );

//    

//    

    

//    

//    int result=sumValue(100);

//    printf("%d\n",result );

    

    

    

    

//    int day =dayOfYear(2000,3,1);

//    printf("%d",day );

    

    

//    int result=number(10045);

//    printf("%d",result);

//    

    

    

    

    

    

    

    

    

    

    return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值