标签:i++ nbsp 排序 oid print ble 七天 += 逆序
用函数封装进行逆序排序
void nixu(int a[], int n)
{
int i;
for(i = 0; i < n/2; i++){
a[i] ^= a[n-1-i];
a[n-1-i] ^= a[i];
a[i] ^= a[n-1-i];
}
}
void ptr_arr(int *a, int n)
{
int i;
for(i = 0; i < n; i++)
printf("%d ", *(a++));
printf("\n");
}
int main()
{
int a[5] = {1,2,3,4,5};
ptr_arr(a, 5);
nixu(a, 5);
ptr_arr(a, 5);
}
函数封装进行互换
void swap(int *a,int *b)
{
int tem = *a;
*a = *b;
*b = tem;
}
int main()
{
int a = 10, b= 20;
printf("a:%d , b:%d\n", a, b);
swap(&a,&b);
printf("a:%d , b:%d\n", a, b);
}
double add(double a, double b)
{
double sum = a + b;
return sum;
}
int main()
{
double a = 2.4, b = 3.1;
double sum = add(b, a);
printf("%.2f \n", add(sum,add(sum,a)));
}
用指针数组求二维数组的和
int main()
{
int a[3][4] = {1,2,3,4,5,6,7,8,9,10,11,12};
int i, j;
int (*p)[4] = a;
int sum = 0;
for(i = 0; i < 3; i++){
for(j = 0; j < 4; j++){
sum += *(*(p+i)+j);
}
}
printf("%d \n", sum);
}
标签:i++ nbsp 排序 oid print ble 七天 += 逆序
原文地址:https://www.cnblogs.com/doublecheng/p/11192357.html