一、数据类型
int 整型变量:有符号整型,只能处理整数
short int (数值较小的情况下使用,占的内存较小)
long int (数值较大时使用) long long int(更大)
unsigned int(用于只使用非负值的场合)
char 字符变量:用于表示字母及其他字符,也可以表示较小的整数,通常使用8位内存单元
float 浮点变量 :可以处理带有小数点的数据
double 双精度:使用64位长度
二、各种数据类型的打印
int %d;
short int %ho;
long int %ld;
unsigned int %u;
char %c;
float %f;
double %a/%f;
各个进制的打印及显示
八进制:%0;
十六进制:%0x;
类型大小的计算:
size of 计算字节长度
三、非打印字符
练习:
NO.1
#include<stdio.h>
int main()
{
int n;
printf("Enter a ASCII: ");
scanf("%d",&n);
printf("The character is %c\n",n);
return 0;
}
NO.2
#include<stdio.h>
int main()
{
printf("\a By the Great Pumpkin, what was that!\a \n");
return 0;
}
NO.3
#include<stdio.h>
int main()
{
float n = 21.29;
printf("The input is %f or %e.\n",n,n);
return 0;
}
NO.4
#include<stdio.h>
int main()
{
float n;
printf("Your age:");
scanf("%f",&n);
n = n*3.156e7;
printf("Time: %e\n",n);
return 0;
}
NO.5
include<stdio.h>
int main()
{
float n,m;
printf("Enter a number:");
scanf("%f",&n);
m=n*2.54;
printf("%f inch = %f centimeter\n",n,m);
return 0;
}
欢迎其他朋友留言交流!