作业帮 > 综合 > 作业

编写一个C程序,输入ABC三个数,输出最大

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/04/28 22:11:11
编写一个C程序,输入ABC三个数,输出最大
/* Note:Your choice is C IDE */
#include "stdio.h"
void main()
{
    int a,b,c,max;
    printf("please input a,b,c\n");
    scanf("%d,%d,%d,&a,&b,&c");
    max=a;
    if(max<b)
       max=b;
    if(max<c)
    max=c;
    printf("the largerst number is %d\n,max");
    return 0;
}

为什么会出现这种情况,我知道是内存的问题,是不是输入错误了?
scanf("%d,%d,%d,&a,&b,&c");改成
scanf("%d,%d,%d“,&a,&b,&c);
printf("the largerst number is %d\n,max");改成
printf("the largerst number is %d\n",max);
要说这个是为什么,是因为scanf和printf的变参引起的,这两个函数的第一个参数为字符串,后面的参数都需要靠解析这个字符串才能知道.那么你的字符串里有一个%d这种标识,他就认识第二个参数是int型的
而本程序中,你都放到引号里,在取字符串的时候,这只算第一个参数,相当于没给出后面的参数.然后在解析参数的时候,就发生了空引用.