C语言 用字符数组编程实现找出字符串中最大的那个字符元素,并输出该字符及其对应的ASCII码值

2025-03-10 23:54:02
推荐回答(1个)
回答1:

C语言程序:

#include 
#include 

#define MAX 80

void main()
{
char arr[MAX + 1];
char max;
int len;
int i;

printf("Input a string:\n");
gets(arr);

max = '\0';
len = strlen(arr);
for(i=0; i {
if(arr[i] > max)
{
max = arr[i];
}
}

printf("The largest character is \'%c\'.The ASCII is %d.\n", max, max);
}

 运行测试: