返回列表 發帖

01怎樣應用c++ 數學函數?

  1. #include<bits/stdc++.h>
  2. using namespace std;

  3. int main()
  4. {
  5.     cin.tie(0);    cin.sync_with_stdio(0);

  6.     int a=5;
  7.     double b=4;
  8.     float c=5.34;
  9.     int d=-7;

  10.    cout<<a<<"的 "<<b<<"次方是"<<pow(a,b)<<endl;
  11.    cout<<b<<"開根號後的值是"<<sqrt(b)<<endl ;
  12.    cout<<c<<"小數無條件捨去後的值是"<<floor(c)<<endl;
  13.    cout<<c<<"小數四捨五入後的值是"<<round(c)<<endl;
  14.    cout<<c<<"小數無條件進入後的值是"<<ceil(c)<<endl;
  15.    cout<<d<<"的絕對值是"<<abs(d)<<endl;
  16.    return 0;
  17. }
複製代碼
May

數學函式是從cmath來的

TOP

#include<bits/stdc++.h>
是C++的萬用標頭檔=>包含了目前c++所包含的所有標頭檔案

  1. 1 #include <iostream>
  2. 2 #include <cstdio>
  3. 3 #include <fstream>
  4. 4 #include <algorithm>
  5. 5 #include <cmath>
  6. 6 #include <deque>
  7. 7 #include <vector>
  8. 8 #include <queue>
  9. 9 #include <string>
  10. 10 #include <cstring>
  11. 11 #include <map>
  12. 12 #include <stack>
  13. 13 #include <set>
複製代碼

TOP

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    //cin.tie(0); cin.sync_with_stdio(0);
    int a=5,b=4,d=-7;
    float c=5.34;

    cout<<a<<"的"<<b<<"次方是"<<pow(5,6)<<endl;
    cout<<b<<"開根號後的值是"<<sqrt(b)<<endl;
    cout<<c<<"小數無條件捨去後的值是"<<floor(c)<<endl;
    cout<<c<<"小數四捨五入後的值是"<<round(c)<<endl;
    cout<<d<<"的絕對值是"<<abs(d)<<endl;
    return 0;  
}

TOP

本帖最後由 朱春男 於 2022-12-10 14:37 編輯
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.     double a=5,b=4,d=-7;
  7.     float c=5.34;

  8.     cout<<a<<"的"<<b<<"次方是"<<pow(5,6)<<endl;
  9.     cout<<b<<"開根號後的值是"<<sqrt(b)<<endl;
  10.     cout<<c<<"小數無條件捨去後的值是"<<floor(c)<<endl;
  11.     cout<<c<<"小數四捨五入後的值是"<<round(c)<<endl;
  12.     cout<<d<<"的絕對值是"<<abs(d)<<endl;
  13.     system("pause");
  14.     return 0;  
  15. }
複製代碼

TOP

本帖最後由 朱春珠 於 2022-12-10 14:44 編輯
  1. #include<iostream>
  2. #include<cmath>
  3. using namespace std;

  4. int main()
  5. {
  6.     double a=5;
  7.     double b=4;
  8.     float c=5.34;
  9.     int d=-7;

  10.    cout<<a<<"的 "<<b<<"次方是"<<pow(a,b)<<endl;
  11.    cout<<b<<"開根號後的值是"<<sqrt(b)<<endl ;
  12.    cout<<c<<"小數無條件捨去後的值是"<<floor(c)<<endl;
  13.    cout<<c<<"小數四捨五入後的值是"<<round(c)<<endl;
  14.    cout<<c<<"小數無條件進入後的值是"<<ceil(c)<<endl;
  15.    cout<<d<<"的絕對值是"<<abs(d)<<endl;
  16.    return 0;
  17. }
複製代碼

TOP

返回列表