m0_62927409 2022-01-03 21:08 采纳率: 81%
浏览 20
已结题

请问应该怎么改,输出结果是不对的

编程实现找出字符串中最大字符元素并输出该元素及其对应的ASCII值.
****要求输入提示信息为:
"Input a string:\n"
****输出格式要求为:
"The largest character of "%s" is '%c' ,The ASCII is %d."

程序运行示例:
Input a string:↙
I am a student.
The largest character of "I am a student." is 'u' ,The ASCII is 117.↙
#include<stdio.h>
#include<string.h>
#define N 100
int main()
{
char a[N];
gets(a);
char temp=a[0];
int i;
for(i=0;i!='\0';i++)
{
if(a[i]>temp)
{
temp=a[i];
}

}
printf("The largest character of \"%s\" is \'%c\' ,The ASCII is %d.",a,a[i],a[i]);
return 0;

}

  • 写回答

3条回答 默认 最新

  • -Undefined_ 2022-01-03 21:13
    关注

    i!='\0' 改为 a[i]!='\0'
    printf("The largest character of "%s" is '%c' ,The ASCII is %d.",a,a[i],a[i]);
    改为:
    printf("The largest character of "%s" is '%c' ,The ASCII is %d.",a,temp,temp);

    #include<stdio.h>
    #include<string.h>
    #define N 100
    int main() {
        char a[N];
        gets(a);
        char temp = a[0];
        int i;
        for(i = 0; a[i] != '\0'; i++) {
            if(a[i] > temp) {
                temp = a[i];
            }
    
        }
        printf("The largest character of \"%s\" is \'%c\' ,The ASCII is %d.", a, temp, temp);
        return 0;
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 1月11日
  • 已采纳回答 1月3日
  • 创建了问题 1月3日

悬赏问题

  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?