1. fun: 利用插入排序法对字符串中的字符从小按到大的顺序进行排序。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    void  insert(char  *aa)
    { int i,j,n; char ch;
    /**********found**********/
    n=strlen(aa);
    for( i=1; i<n;i++ ) {
    /**********found**********/
    ch=aa[i];
    j=i-1;
    while ((j>=0) && ( ch<aa[j] ))
    { aa[j+1]=aa[j];
    j--;
    }
    aa[j+1]=ch;
    }
    }
  2. fun: 计算s所指字符串中含有t所指字符串的数目,并作为函数值返回

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    int  fun(char  *s,  char  *t)
    { int n;
    char *p , *r;
    n=0;
    while ( *s )
    { p=s;
    /*********found**********/
    r=t;
    while(*r)
    if(*r==*p) { r++; p++; }
    else break;
    /*********found**********/
    if(*r== 0)
    n++;
    s++;
    }
    return n;
    }
  3. fun: 找出n的所有因子,统计因子的个数,并判断n是否是“完全数”。当一个数的因子之和恰好等于这个数的本身时,就称为“完全数”。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    int  fun(int  n, int  a[], int  *k)
    { int m=0, i, t;
    t = n;
    /**********found**********/
    for( i=1; i<n; i++ )
    if(n%i==0)
    { a[m]=i; m++; t=t - i; }
    /**********found**********/
    *k=m;
    /**********found**********/
    if ( t==0 ) return 1;
    else return 0;
    }
  4. fun: 判断输入的任何一个正整数n,是否等于某个连续正整数序列之和。若是,则输出所有可能的序列。否则输出“不能分解”

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void fun( int  n )
    { int j, b, c, m, flag=0;
    for (b=1; b<=n/2; b++) {
    /**********found**********/
    m=n;
    c = b;
    while (m !=0 && m>=c) {
    /**********found**********/
    m = m - c; c++;
    }
    /**********found**********/
    if ( m==0)
    { printf("%d=", n);
    for (j=b; j<c-1; j++) printf( "%d+", j );
    printf("%d\n", j);
    flag=1;
    }
    }
    if(flag==0)
    printf("不能分解\n");
    }
  5. 调用fun函数输出字符串,当奇数次调用时要求把字符串中的小写字母转换成大写字母,偶数次调用时按输入字符串的逆序输出字符串

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    #include   <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #pragma warning (disable:4996)
    void fun( char *s )
    { int i;
    /**********************found***********************/
    static int n = 1;
    if ( n++ %2 )
    /**********************found***********************/
    for(i=0;i<strlen(s);i++)
    printf("%c", islower(s[i]) ? toupper(s[i]) : s[i]);
    else
    /**********************found***********************/
    for (i = strlen(s)-1; i>=0; i--)
    printf("%c", s[i]);
    }
  1. fun:将字符串s1和s2合并形成新字符串s3,假定s1字符串的长度为L1,s2的第L2-i-1个字符插入到原s1的第i个字符后,如果s1比s2长,则s1剩余的部分按在s1中的顺序放在新表s3后,如果s2比s1长,则s2剩余的部分安在s2中的顺序的逆序放在新生成的s3后。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    void fun(char *s1, char *s2, char *s3)
    {
    int i,j,L2;
    L2=strlen(s2);
    for(i=0,j=0;(s1[i]!='\0')&&(s2[i]!='\0');i++,j=j+2)
    {
    s3[j]=s1[i];
    /***********found**********/
    s3[j+1]=s2[L2-1-i];
    }
    /***********found**********/
    if(s1[i]!='\0')
    for(;s1[i]!='\0';i++,j+=1)
    s3[j]=s1[i];
    else if (s2[i]!='\0')
    for(;s2[i]!='\0';i++,j++)
    s3[j]=s2[L2-1-i];
    /***********found**********/
    s3[j]='\0';
    }