首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

输入二个数,按数值大小排列 为什么输出的数字前面一个都是0呢

2013-11-06 
输入2个数,按数值大小排列 为什么输出的数字前面一个都是0呢#include stdio.hvoid main(){float a,b,ts

输入2个数,按数值大小排列 为什么输出的数字前面一个都是0呢
#include "stdio.h"
void main()
{
    float a,b,t;
    scanf("%f,%f",&a,&b);
    if(a>b){t=a;a=b;b=t;}
    printf("%5.2f,%5.2f",a,b);
} 2个数?按大小排列的问题
[解决办法]
scanf的时候,你用"%f,%f"的格式,那么在输入的时候需要加一个逗号,例如:


1.2,3.45


引用:
#include "stdio.h"
void main()
{
    float a,b,t;
    scanf("%f,%f",&a,&b);
    if(a>b){t=a;a=b;b=t;}
    printf("%5.2f,%5.2f",a,b);
}

[解决办法]
引用:
scanf的时候,你用"%f,%f"的格式,那么在输入的时候需要加一个逗号,例如:

1.2,3.45


Quote: 引用:

#include "stdio.h"
void main()
{
    float a,b,t;
    scanf("%f,%f",&a,&b);
    if(a>b){t=a;a=b;b=t;}
    printf("%5.2f,%5.2f",a,b);
}


+1
[解决办法]

scanf()函数。 格式化输入函数,调用的时候什么样格式,输入的时候一同样的格式输入!

[解决办法]
google printf() 函数,看看printf("%5.2f,%5.2f",a,b); 中5.2表示什么意思


A number specifying a minimum field width. The converted argument will be printed in a field at least this wide, and wider if necessary. If the converted argument has fewer characters than the field width it will be padded on the left (or right, if left adjustment has been requested) to make up the field width. The padding character is normally space, but is 0 if the zero padding flag is present.

热点排行