详细排列
视频知识点
代码
输出单个字符putchar函数(indexP701.c)
//title:输出单个字符
//字符数据的输入输出(putchar函数(字符输出函数))
#include <stdio.h>
void main01()
{
char a='B',b='o',c='k';
putchar(a);putchar(b);putchar(b);putchar(c);putchar('\t');
putchar(a);putchar(b);
putchar('\n');
putchar(b);putchar(c);
putchar('\n');
}
输入单个字符getchar函数(indexP702.c)
//title:输入单个字符
//字符数据的输入输出(getchar函数(字符输入函数))
#include <stdio.h>
void main02()
{
char c;
printf("input a character\n");
c=getchar();
putchar(c);
putchar('\n');//用putchar("\n");则会多一个[而不是换行,具体原因不清楚
}
格式输入输出printf函数(indexP701.c)
//title:格式输入与输出
//printf函数(格式输出函数)
#include <stdio.h>
void main03()
{
int a=88,b=89;
printf("%d %d\n",a,b);//88 89
printf("%d,%d\n",a,b);//88,89
printf("%c,%c\n",a,b);//X,Y
printf("a=%d,b=%d",a,b);//a=88,b=89
}
不同格式输入输出(indexP701.c)
//title:格式输入与输出
//printf函数(格式输出函数)
#include <stdio.h>
void main()
{
int a=15;
float b=123.1234567;
double c=12345678.1234567;
char d='p';
printf("a=%d,%5d,%o,%x\n",a,a,a,a);
printf("b=%f,%lf,%5.4lf,%e\n",b,b,b,b);
printf("c=%lf,%f,%8.4lf\n",c,c,c);
printf("d=%c,%8c\n",d,d);
//a=15, 15,17,f
//b=123.123459,123.123459,123.1235,1.231235e+002
//c=12345678.123457,12345678.123457,12345678.1235
//d=p, p
}