gpt4 book ai didi

c - Short 不起作用,但 int 可以吗?

转载 作者:太空宇宙 更新时间:2023-11-04 08:07:24 25 4
gpt4 key购买 nike

#include<stdio.h>

int main()
{
short a, b, c;
printf("Enter the values of a, b and c: ");
scanf(" %d %d %d ", &a, &b, &c);
if( a<b && a<c )
printf( "a is smaller" );
else if( b<a && b<c )
printf( "b is smaller" );
else
printf( "c is smaller" );
return 0;
}

对于输入a=10, b=12, c=13,它给出输出“c is smaller”?

当我用 int 替换 short 时,它给出了正确的输出。我也试过 %h, %i 但它输出相同。

出了什么问题?

最佳答案

使用:

scanf(" %hi %hi %hi ", &a , &b , &c);

%d 用于 int%hi 用于 short 数据类型

关于c - Short 不起作用,但 int 可以吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41831834/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com