在 c 语言中输入和输出需要一个占位符。
%d - int
%ld - long int
%c - char
%f - float
%u - 无符号数
%hd - 短整型 short
%lf - double
%x - 十六进制输出 int 或者 long int 或者 short int
%o - 八进制输出
%s - 字符串
输出:
#include <stdio.h>
#include <stlib.h>
main(){
int i = 3;
float f = 3.14;
double d = 3.1415926535;
char c = 'f';
short s = 123;
printf("int = %d\n",i);
printf("float = %f\n",f);
printf("double = %lf\n",d);
printf("char = %c\n",c);
printf("short = %hd\n",s);
system("pause");
}
输入:
#include <stdio.h>
int main(int argc, char *argv[])
{
printf("请输入一个整数");
int i;
scanf("%d", &i);
printf("输入的数为%d\n", i);
printf("请输入一串字符");
char c[] = {' ',' ',' ',' '};
scanf("%s", c);
printf("输入的字符串为%s", c);
return 0;
}