4.12~4.14

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33528164/article/details/87890140

4.12

void reverse(char str[], int before, int behind){
    int c;
    if(before < behind){
        c = str[before];
        str[before] = str[behind];
        str[behind] = c;
        reverse(str, before + 1, behind-1);
    }
}

4.13


void itoa(int n, char s[]){
    static int i;
   if(n / 10){
       itoa(n / 10, s);
   } else {
       i = 0;
       if( n < 0){
           s[i++] = '-';
       }
   }
   s[i++] = (n % 10) + '0';
   s[i] = '\0';
}

4.14

#include <stdio.h>

#define swap(t, x, y) {  t _z; \
                        _z = y; \
                        y = x; \
                        x = _z; }

int main(){
    int a = 4;
    int b = 5;
    swap(int , a, b);
    printf("a = %d\n", a);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_33528164/article/details/87890140