ch02 格式化与流程控制
格式化 printf printf() 用于打印消息以及变量的值。 c 1 2 3 4 5 6 7 8 #include<stdio.h> int main() { int a = 24; printf("Welcome! \n"); printf("The value of a : %d",a); getchar(); return 0; } sprintf sprintf() 不打印字符串,是将字符值和格式化结构一并存储在一个数组中。 c 1 2 3 4 5 6 7 8 9 10 11 12 13 int main() { char buffer[50]; int a = 10, b = 20, c; c = a + b; sprintf(buffer, "Sum of %d and %d is %d", a, b, c); // The string "sum of 10 and 20 is 30" is stored // into buffer instead of printing on stdout printf("%s", buffer); return 0; } scanf 从标准输入读取用户输入的...