long long int的格式输入与输出

时间:2025-03-14 17:08:01

当做到一道结构体问题时,输出一直错误,找不到原因。问题如下:

typedef struct student
{
	float grade[3];
	long long int number;
}stu;
int main()
{
	stu stu1;
	scanf("%d;%f,%f,%f", &(), &([0]), &([1]), &([2]));
	printf("The each subject score of  No. %d is %.2f, %.2f, %.2f.\n",,[0],[1],[2]);
	return 0;
}

//输入:1410202;77,88,99
//输出:The each subject score of  No. 1410202 is 0.00, 0.00, 0.00.
//预期结果:The each subject score of  No. 1410202 is 77.00, 88.00, 99.00.

这里,就是因为number是long long int类型,而该代码中无论是输入还是输出都是%d,导致输出结果错误。

为了避免这种问题,在对16进制数输入输出时都要用%lld格式输入输出

例:long long int number;

scanf("%lld",&number);

printf("%lld\n",number);