void swapFloat(float *a,float *b){
float temp = *a;
*a = *b;
*b = temp;
}
//数组打印
void printArr(int *arr,int count){
for (int i = 0; i < count; i++) {
printf("%d ",arr[i]);
}
}
//数组前后倒置
void turnArr(int *arr,int count){
int *p = arr;
int temp = 0;
int a =count / 2;
for (int i = 0; i < a; i++) {
temp = p[i];
p[i] = *(p+count-1);
*(p+count-1) = temp;
count--;
}
}
//最大值
void printMax(int *a,int *b,int *c,int *max){
*max = *a > *b ? *a : *b;
*max = *max > *c ? *max : *c;
}
//有一字符串中包含数字与字符,请编程去除数字
void removeNumber(char *arr,int count){
char *p = arr;
for (int i = 0; i < count; i++) {
int num = i;
if (p[i] >= '0'&& p[i] <= '9') {
for (; i < count; i++) {
p[i] = p[i+1];
}
i = num-1;
}
}
}
void removeNumber2(char *arr){
char *p1 = arr;
char *p2 = arr;
for (; *p1 != '\0';p1++) {
if (*p1 < '0' || *p1 > '9') {
*p2 = *p1;
p2++;
}
}
*p2 = *p1;
}
void removeNumber3(char *arr){
char *p1 = arr;
char *p2 = arr;
while (*p1 != '\0') {
if (*p1 < '0' || *p1 > '9') {
*p2 = *p1;
p2++;
}
p1++;
}
*p2 = *p1;
}
int main(int argc, const char * argv[])
{
// 交换 2 个浮点数。
/*
float a = 2.43,b = 5.5;
swapFloat(&a, &b);
printf("a = %.2f b = %.2f\n",a,b);
*/
// 从键盘输入11个整数存入一维数组中,再将该数组的内容前后倒置并输出
/*
printf("请输入11个整数:\n");
int arr[11] = {0};
for (int i = 0; i < 11; i++) {
scanf("%d",&arr[i]);
}
turnArr(arr, sizeof(arr)/sizeof(int));
printArr(arr, sizeof(arr)/sizeof(int));
*/
// 写求三个数中最大数的函数,并调用该函数求出主函数中三个数中的最大数
/*
int a = 10,b = 20,c = 30,max = 0;
printMax(&a,&b,&c,&max);
printf("最大值是:%d ",max);
*/
//有一字符串中包含数字与字符,请编程去除数字
// char arr[] = "h232e445l66l3o3 342worl4d5675675765";
// removeNumber(arr,sizeof(arr)/sizeof(char));
// removeNumber2(arr);
// removeNumber3(arr);
// printf("%s",arr);
return 0;
}
C语言-9
最新推荐文章于 2023-06-29 20:20:49 发布