码迷,mamicode.com
首页 > 其他好文 > 详细

C6_函数多文件管理

时间:2015-07-07 21:04:19      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

//

//  main.m

//  C6_函数多文件管理

//

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

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

//

 

#import <Foundation/Foundation.h>

#import "MyFunction.h" //引头文件

 

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

//    

//    while (a % b != 0) {

//        int remainder = a % b ;

//        a = b;

//        b = remainder;

//        

//    }

//    return b ;

//    

//    

//}

//int strintLen(char str[]){

//    int len=0;

//    while (str[len] != ‘\0‘) {

//        len++;

//    }

//    return len;

//    

//}

 

//// 数组作为参数进行传递

//// 第一部分  传递一个数组名

//// 第二部分需要执行一个数组的有效长度

//void printArr(int arr[],int count){

//    for (int i =0; i<count; i++) {

//        printf("%d ",arr[i]);

//    }

//    printf("\n");

//

//

//}

 

// 通过函数的方式,对一对整形数组进行冒泡排序

//void bubbleSort(int arr[],int count){

//    for (int i=0; i<count; i++) {

//        for (int j=0; j<count-1-i; j++) {

//            if (arr[j]>arr[j+1]) {

//                int temp=0;

//                temp=arr[j];

//                arr[j]=arr[j+1];

//                arr[j+1]=temp;

//            }

//        }

//    }

//}

//

//

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

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

//    

//}

 

 

 

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

   

//    // 1.字符串数组的排序

//    char stuName[4][20]={"zhangsan","lisi","wangwu","liushanshan"};

//    for (int i = 0; i<4-1; i++) {

//        for (int j = 0; j<4-1-i; j++) {

//            if (strcmp(stuName[j], stuName[j+1])>0) {

//                char temp[20]="";

//                // 字符串操作strcpy

//                strcpy(temp, stuName[j]);

//                strcpy(stuName[j], stuName[j+1]);

//                strcpy(stuName[j+1], temp);

//                

//                

//                

//                

//            }

//        }

//    }for (int i=0; i<4; i++) {

//        printf("%s ",stuName[i]);

//    }

    

//   char str[20]="";

//    scanf("%s",str);

//    gets(str);

//    printf("%s",str);

    

 

//      // 回文串

//    for (int i=0; i<strlen(str ) / 2; i++) {

//        if (str[i] != str[]strlen(str)-1-i {

//            printf("不是回文串\n")

//            break;

//        }

//        

//        

//        

//    }

    

    

    // 用函数编写一个程序,输入两个正整数,要求返回最大公约数

    

//    int result=twoNumber(15,17);

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

    

//    // 字符串长度

//    char str[20]="yanglin";

//    printf("%d\n",strintLen(str ));

//

    

//    int arr[6]={1,2,3,4,9};

////    printf("%p\n",&arr[0]);

////    printf("%p\n",arr);

////    printf("%p\n",&arr[1]);

////    printf("%p\n",&arr[2]);

//    printf("%ld\n");

//    printArr(arr,sizeof(arr) / sizeof(int));

    

    

//    int arr[8]={98,1,92,66,12,21,5,7};

//    bubbleSort(arr, 8);

//    for (int i =0; i<8; i++) {

//        printf("%d ",arr[i]);

//    }printf("/n");

//    

//    printf("%d\n",addNum(1, 2 ));

    

    // 多文件的时候.函数调用还是用函数名来进行

//    printf("%d\n",sumValue(100));

    

//    int arr[8]={19,1,27,14,90,65,78,3};

//    // 调用两个函数,排序和打印

//    bubbleSort(arr, 8);

//    printArr(arr, 8);

//    // 函数最大好处就是节省代码,提高代码的重用率

    

//    if (huiWenChuan("level")) {

//       printf("是\n");

//    }

//    else{

//        printf("否\n");

//    }

    

    

//    printf("%d",factorialNum(5));

      

    

    

    int arr[5]={15,78,20,7,6};

    // 1.如果数组中有78这个数字,把这个数字变成100,并且把78这个下标进行返回,没有返回5

    printf("%d\n",checkArr(arr, 5, 78));

    

    

    

    

    

    

    

    

    

    

    

    

    

    return 0;

}

 

 

 

 

 

 

 

 

 

 

.h文件

//

//  MyFunction.h

//  C6_函数多文件管理

//

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

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

//

 

#import <Foundation/Foundation.h>

 

// 在.h里,我们写函数的声明

// 声明相当于说明书目录,具体的功能是实现和介绍

//int sumValue(int n);

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

//int twoNumber(int a,int b);

// 对整形的一位数组进行冒泡排序

//void bubbleSort(int arr[],int count);

////对整形的一位数组进行打印操作

//void printArr(int arr[],int count);

// 回文串

// 字符串本身有结束标志,所以不需要再传一个长度

BOOL huiWenChuan(char str[]);

// 找到两个整数中的最大值,并返回

int maxInTwo(int a,int b);

// 三个整数最大值,并且返回

int maxInThree(int a,int b,int c );

//四个数最大值

int maxInFour(int a,int b,int c,int d );

//五个数最大值

int maxInFive(int a,int b,int c,int d,int e );

//

void test();

// 计算一下阶

int factorialNum(int n);

//

int checkArr(int arr[],count,int num);

 

 

 

 

.m文件

//

//  MyFunction.m

//  C6_函数多文件管理

//

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

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

//

 

#import "MyFunction.h"

//int sumValue(int n) {

//    int sum=0;

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

//        sum += i;

//    }

//    return sum;

//}

//

//int dayOfYear(int year, int month,int 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;

//            

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

//                if (month > 2){

//                    day =day + 1;

//                }

//            }

//        default:

//            break;

//    }return day;

//}

 

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

//    int sum = a+b;

//    int sub = a-b;

//    int mul = a*b;

//    int div = a/b;

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

 

// 如果复制过来之后有声明的分号,把分号一定删除掉

//void bubbleSort(int arr[],int count){

//    for (int i=0; i<count-1; i++) {

//        for (int j=0; j<count-1-i; j++) {

//            if (arr[j]>arr[j+1]) {

//                int temp = 0;

//                temp=arr[j];

//                arr[j]=arr[j+1];

//                arr[j+1]=temp;

//            }

//        }

//    }

//    

//    

//}

////对整形的一位数组进行打印操作

//void printArr(int arr[],int count){

//    for (int i = 0; i< count; i++) {

//        printf("%d ",arr[i]);

//    }

//}

 

//BOOL huiWenChuan(char str[]){

//    for (int i=0; i<strlen(str) / 2; i++) {

//        if (str[i] != str[strlen(str)-i-1]) {

//            return NO;

//        }

//    }return YES;

//}

 

 

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

//    return  a > b ? a : b;

//}

//

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

//    // 函数的嵌套调用

//    int max =maxInTwo(a , b);

//    max = maxInTwo(max, c);

//    return max;

//}

//

//int maxInFour(int a,int b,int c,int d ){

//    int max = maxInThree(a, b, c);

//    max= maxInTwo(max , d);

//    return max;

//}

//

//int maxInFive(int a,int b,int c,int d,int e ){

//    int max=maxInFour(a, b, c, d);

//    max=maxInTwo(max , e);

//    return max;

//}

// 如果写递归的话,一定要注意,在自己调用自己的时候,一定要给程序留一个结束的出口

//void test(){

//    test();

//}

 

//int factorialNum(int n){

//    // 首先给函数找一个结束的出口

//    if (n==1) {

//        return 1;

//    }return factorialNum(n-1)*n;

//    

//}

int checkArr(int arr[],count,int num){

    for (int i=0; i<count; i++) {

        if (arr[i]== num) {

            arr[i]=100;

            return i;

        }

    }return 5;

}

 

C6_函数多文件管理

标签:

原文地址:http://www.cnblogs.com/zhaozhicheng/p/4628384.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!