找到字符数组中的最大字符

来源:互联网 发布:java字符串包含字符串 编辑:程序博客网 时间:2024/06/06 07:26
#include <stdio.h>
#include <stdlib.h>
main()
{
    char string[81];
    int i=0;
    char max;
    printf("Input a string:");  //1
    printf("\n");
    gets(string);
    max=string[i];      //1
    while(string[i]!='\0')      //2
    {
        i=i+1;
        if(string[i]>max)        //2
           max=string[i];       //1
    }
    printf("The largest character of \"%s\" is \'%c\' ,The ASCII is %d.",string,max,max);   //2
}
0 0