c++硬核学习 一些数学运算 用cmake

本文通过C++代码示例详细介绍了cmath库中常用的数学运算,包括三角函数、对数、幂、绝对值等操作,展示了不同数据类型的输入如何影响运算结果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一些cmath的数学运算,我很懒,所以。。。。
在这里插入图片描述

例如

// helloworld.cpp: 定义控制台应用程序的入口点。
//
#include <iostream>
#include <cmath>
using namespace std;
//命名空间

int main()
{

    int c=100;
    double b = 5.12;
    short k = -5;
    cout << sin(c) << "    " << typeid(sin(c)).name() << "    " << typeid(c).name() << endl;
    cout << cos(c) << "    " << typeid(cos(c)).name() << "    " << typeid(c).name() << endl;
    cout << tan(c) << "    " << typeid(tan(c)).name() << "    " << typeid(c).name() << endl;
    cout << log(c) << "    " << typeid(log(c)).name() << "    " << typeid(c).name() << endl;
    cout << pow(c,b) << "    " << typeid(pow(c,b)).name() << "    " << typeid(c).name() << typeid(b).name() << endl;
    cout << abs(k) << "    " << typeid(abs(k)).name() << "    " << typeid(k).name() << endl;
    cout << fabs(k) << "    " << typeid(fabs(k)).name() << "    " << typeid(k).name() << endl;
    cout << floor(c) << "    " << typeid(floor(c)).name() << "    " << typeid(k).name() << endl;

    return 0;
}

输出

-0.506366    double    int
0.862319    double    int
-0.587214    double    int
4.60517    double    int
1.7378e+10    double    intdouble
5    int    short
5    double    short
100    double    short
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值