02数据的类型、数据的输入输出(部分)
#include <stdio.h>
int main() {
????int i=5;
????float j=i/2;//这里做的是整型运算,因为左右操作数都是整型
????float k=(float)i/2;//强制类型转换(float)i
????printf("%f\n",j);
????printf("%f\n",k);
????return 0;
}
#include <stdio.h>
int main() {
????int age=21;
????printf("Hello %s, you are %d years old\n","Bob",age);
????return 0;
}
#include <stdio.h>
int main() {
????int i=10;
????float f=96.3;
????printf("student number=%d score=%f\n",i,f);
????printf("student number=%3d score=%5.2f\n",i,f);
????printf("student number=%-3d score=%5.2f\n",i,f);//默认左对齐,添加负号右对齐
????printf("%s\n","hello");
????printf("%10s\n","hello");
????printf("%-10s\n","hello");
????return 0;
}
#include <stdio.h>
int main() {
????int i=123;
????printf("%d\n",i);//十进制输出
????printf("%o\n",i);//八进制输出
????printf("%x\n",i);//十六进制输出
????return 0;
}
#include <stdio.h>
int main() {
????int i=10;
????scanf("%d",&i);//scanf用来读取标准输入,scanf需要把标准输入的内容存放到某个变量空间,因此变量必须取地址
????printf("i=%d\n",i);
????return 0;
}
#include <stdio.h>
int main() {
????int i;
????char c;
????scanf("%d",&i);
????printf("i=%d\n",i);
????scanf("%c",&c);
????printf("c=%c\n",c);
????return 0;
}
#include <stdio.h>
int main() {
????int i;
????char c;
????scanf("%d",&i);//scanf用来读取标准输入,scanf需要把标准输入的内容存放到某个变量空间,因此变量必须取地址
????printf("i=%d\n",i);
????fflush(stdin);//清空标准输入缓冲区
????scanf("%c",&c);
????printf("c=%c\n",c);
????return 0;
}
#include <stdio.h>
int main() {
????int i;
????float j;
????scanf("%d",&i);
????printf("i=%d\n",i);
????scanf("%f",&j);
????printf("j=%f\n",j);
????return 0;
}
#include <stdio.h>
int main() {
????int i,ret;
????float f;
????char c;
????ret=scanf("%d %c%f",&i,&c,&f);//%c之前增加空格
????printf("i=%d,c=%c,f=%5.2f\n",i,c,f);
????return 0;
}
#include<stdio.h>
int main() {
????int i,ret;
????float f;
????char c;
????ret=scanf("%d%c%f",&i,&c,&f);//%c之前不增加空格
????printf("i=%d,c=%c,f=%5.2f\n",i,c,f);
????return 0;
}