常用scanf和printf格式码

时间:2022-01-10 19:57:33
#include <stdio.h>

int main()
{
	int i;
	long l;
	unsigned long ul;
	float f;
	double d;
	char c;
	char s[10];
	
	printf("input a char:\t");
	scanf("%c", &c);
	printf("c = %c\n", c);
	
	printf("input a string:\t");
	scanf("%s", s);
	printf("s = %s\n", s);
	
	printf("input a int(-2147483647~2147483647):\t");
	scanf("%d", &i);
	printf("&i = %x\n", &i);
	printf("i = %d\n", i);
	printf("i = 0%o\n", i);
	printf("i = 0x%x\n", i);

	printf("input a long(-2147483647~2147483647):\t");
	scanf("%ld", &l);
	printf("l = %ld\n", l);

	printf("input an unsigned long(0~4294967295):\t");
	scanf("%lu", &ul);
	printf("ul = %lu\n", ul);

	printf("input a float:\t");
	scanf("%f", &f);
	printf("f = %f\n", f);

	printf("input a double:\t");
	scanf("%lf", &d);
	printf("d = %.8f\n", d);
}