C.6

.m

//1)写一个函数,实现给数组中的元素随机赋值。

void valArr(int a[],int count) {

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

        a[i] = arc4random() % 11 + 10;

    }

}

//2)写一个函数,实现给数组排序,升序序列。

void rankArr(int a[],int count) {

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

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

            if (a[j] > a[j + 1]) {

                int temp = a[j];

                a[j] = a[j + 1];

                a[j + 1] = temp;

            }

        }

    }

}

//3)写一个函数,实现将数组元素输出。

void outArr(int a[],int count) {

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

        printf("%d ", a[i]);

    }

}

//求数组中的最大值

int maxArr(int a[],int count) {

    int max = 0;//存储数组中的最大值

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

        max = max > a[i] ? max : a[i];

    }

    return max;

}

//求数组中所有元素的和

int sumArr(int a[],int count) {

    int sum =0;//存储数组中所有元素的和

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

        sum += a[i];

    }

    return sum;

}

//2.自己实现strcpy函数。

void strcpy1(char a[],char b[]) {

    int i = 0;

    while ( b[i] != '\0') {

        a[i] = b[i];

        i ++;

    }

}

//2.自己实现strcpy以及strlen函数。

int strlen1(char a[]) {

    int i = 0;

    while (a[i] != '\0') {

        i ++;

    }

    return i;

}

//4.写一个函数,实现将tom is cat反向打印成 cat  is tom


void strtom(char cat[][10]) {

    char a[10] = {0};

    strcpy1(a, cat[0]);

    strcpy1(cat[0], cat[2]);

    strcpy1(cat[2], a);

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值