/* 创建时间:20171221
创建人:fangweijun(773714759@qq.com)
功能:将华氏法温度转化为摄氏法温度 (公式:c=5/9(f-32))
位置:C程序设计(第四版)2010年6月第四版 37页例3.1
*/
#include<stdio.h>
int main()
{
float f,c;
f=64.0;
c=(5.0/9)*(f-32);
printf("f=%f\nc=%f\n",f,c);
return 0;
}
/*Dev-c++输出结果:
f=64.000000
c=17.777779
*/
/* 创建时间:20171221
创建人:fangweijun(773714759@qq.com)
功能:计算一年后的利息和
(活期存款一年后利息和:p1=p0(1+r1);
一年定期存款一年后利息和:p2=p0(1+r2);
两次半年定期存款一年后的利息和:p3=p0(1+r3/2)(1+r3/2))
位置:C程序设计(第四版)2010年6月第四版 38页例3.2
*/
#include<stdio.h>
int main()
{
float p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;
p1=p0*(1+r1);
p2=p0*(1+r2);
p3=p0*(1+r3/2)*(1+r3/2);
printf("p1=%f\np2=%f\np3=%f\n",p1,p2,p3);
return 0;
}
/*Dev-c++输出结果:
p1=1003.599976
p2=1022.500061
p3=1019.897949
*/
/* 创建时间:20171221
创建人:fangweijun(773714759@qq.com)
功能:计算整型数据字节数(由编译系统决定)
位置:C程序设计(第四版)2010年6月第四版 45页
*/
#include<stdio.h>
int main()
{
float s,i,l,ll,us,ui,ul,ull;
s=sizeof(short);//短整型
i=sizeof(int);//基本整型
l=sizeof(long);//长整型
ll=sizeof(long long);//双长整型
us=sizeof(unsigned short);//无符号短整型
ui=sizeof(unsigned int);//无符号基本整型
ul=sizeof(unsigned long);//无符号长整型
ull=sizeof(unsigned long long);//无符号双长整型
printf("s=%f\ni=%f\nl=%f\nll=%f\nus=%f\nui=%f\nul=%f\null=%f\n",s,i,l,ll,us,ui,ul,ull);
}
/*Dev-c++输出结果:
s=2.000000
i=4.000000
l=4.000000
ll=8.000000
us=2.000000
ui=4.000000
ul=4.000000
ull=8.000000
*/
/* 创建时间:20171221
创建人:fangweijun(773714759@qq.com)
功能:无符号整型存储负数的问题
位置:C程序设计(第四版)2010年6月第四版 47页
*/
#include<stdio.h>
int main()
{
unsigned short s=-1;
unsigned int i=-1;
printf("%d\n",s);//按位取反加1
printf("%d\n",i);//编译器的警告输出-1
}
/*Dev-c++输出结果:
65535
-1
*/
/* 创建时间:20171221
创建人:fangweijun(773714759@qq.com)
功能:无符号字符变量
位置:C程序设计(第四版)2010年6月第四版 49页
*/
#include<stdio.h>
int main()
{
unsigned char c=128;
char b=255;
unsigned char ub=255;
printf("%c\n",c);//中文系统不会显示出127以后的部分字符(测试结果为128)
printf("%d\n",b);//出现警告,Dev-c++把char默认为signed char类型
printf("%d\n",ub);//正常输出
}
/*Dev-c++输出结果:
€
-1
255
*/
/* 创建时间:20171221
创建人:fangweijun(773714759@qq.com)
功能:计算浮点型数据字节数(由编译系统决定)
位置:C程序设计(第四版)
C程序设计 第四版(谭浩强)-学习笔记-第二天
最新推荐文章于 2024-05-22 21:35:04 发布