实数

// 实数.cpp : Defines the entry point for the console application.
//


#include "stdafx.h"
#include <stdio.h>


int main1(int argc, char* argv[])
{
float fl=10.5; //赋值号可以自动进行类型转换
printf("%f\n",fl);
printf("%d\n",sizeof(10.5)); //占8个字节说明是一个double类型的双精度
printf("%d\n",sizeof(10.5f));//占4个字节单精度
return 0;
}


void main2()
{
//int num=3/5; //3/5是小数自动进行类型转换就成了0;
//printf("%d\n",num);
int num=10.5;
printf("%d\n",num);//赋值号自动进行类型转换
printf("%f\n",num);//num就成为int类型的所以按照%f输出整数就是解析错误
}




void main3()
{
float fl=19e8; // 19*10^8 E代表指数为10
float f1=19e-2;// 同样也可以是负数
//float f2=19e-2.5;//指数不能实数只能是整数可以有正负


printf("%f,%f",fl,f1);


}




void main4()
{
float f1=1.000000000001;
float f2=1.00000000000002;
/*double f1=1.000000000001;
double f2=1.00000000000002*/;
printf("%d\n",3==3);
printf("%d\n",3==3.1); //成立为1不成立为0
printf("%d\n",f1==f2); //有效数字为6-7位
}


#include <float.h> //保存浮点数的极大与极小
#include <limits.h>//保存整数的极大与极小
void main5()
{
//long double  大于等于double 在服务器上占16个字节
printf("%d,%d,%d\n",sizeof(float),sizeof(double),sizeof(long double));
//float与double是没有有无符号的
printf("%f\n%.100f\n",FLT_MAX,FLT_MIN); //%f默认输出6位
printf("%lf\n%.500lf\n",DBL_MAX,DBL_MIN);
}


 
void main6()
{
printf("%d\n%f\n",INT_MAX,FLT_MAX);

}

********************************************

#include "stdafx.h"
#include <math.h>
#include <stdio.h>




void main()
{
double a=3,b=4,c=5;// c不能大于等于a+b之和
double p=(a+b+c)/2;//半周长
double area=sqrt(p*(p-a)*(p-b)*(p-c));
printf("面积:%f\n",area);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值