printf()與占位符
c 語言中輸入輸出都是靠占位符來指定的
%d - int
%ld - long int
%c - char
%f - float
%lf - double
%x - 十六進(jìn)制輸出 int 或者long int 或者short int
%o - 八進(jìn)制輸出
%s - 字符串
%#x - 0x開頭的16進(jìn)制
int i = 10;
printf((“%d”, i);//輸入函數(shù)
scanf(“%d”,&len);//輸入函數(shù)
練習(xí)
#include<stdio.h>
int main(){
int i =308;
long l = 355555556;
char c = 'A';
float f = 3.1415;
double d = 3.199999;
printf("i=%d\n",i);
printf("l=%ld\n",l);
printf("c=%c\n",c);
printf("f=%f\n",f);
printf("d=%lf\n",d);
printf("i的16進(jìn)制是%#x\n",i);
//定義一個長度為20的字符數(shù)組
char arr[20];
// 鍵盤輸入的函數(shù)
int j =0;
for(;j<4;j++){
scanf("%c", &arr[j]);
}
arr[j]=0;//printf的實現(xiàn)是遇到0之后就會停止打印
printf("arr數(shù)組中的元素是 %s\n", arr);
system("pause");
}