當前位置:編程學習大全網 - 電腦編程 - C語言 用字符數組編程實現找出字符串中最大的那個字符元素,並輸出該字符及其對應的ASCII碼值

C語言 用字符數組編程實現找出字符串中最大的那個字符元素,並輸出該字符及其對應的ASCII碼值

C語言程序:

#include?<stdio.h>

#include?<string.h>

#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<len;?i++)

{

if(arr[i]?>?max)

{

max?=?arr[i];

}

}

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

} 運行測試:

  • 上一篇:飛機模型材料
  • 下一篇:測繪是做什麽的呢?
  • copyright 2024編程學習大全網