.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);
}