C 基礎程式設計DAY4 night

2021-09-29 16:31:43 字數 579 閱讀 2876

我的**

//求和:s = 1*1 + 2*2 + 3*3 + ... + 100*100

//印度國王的獎勵,求和:s = 1 + 2 + 2² + 2³ + …… + 2的63次方

#include

#include

#include

using

namespace std;

intgetsum

(int n)

return sum;

}//int getsum2(int n)

double

getsum2

(int n)

return sum;

}int

main()

題源鏈結

1、函式pow()、sqrt()在math.h中,pow(2.0, 2)底數為浮點數,指數為整數;

2、s = 1 + 2 + 2² + 2³ + …… + 2的63次方的和超過int型別的最大值,所以函式改為double型別;

c/c++中各種型別int、long、double、char表示範圍(最大最小值)

C 基礎程式設計DAY2(day)

我的 求方程ax bx c 0的根 include include include using namespace std double fun int a,int b,int c else else else return0 int main 判斷二元一次方程有無實根條件 a 0 b 4ac 0 ...

C 基礎程式設計DAY7 day

我的 輸入20個數,統計其中正數 負數和零的個數 include include using namespace std intcount xyz int x 0,y 0,z 0 for int i 0 i 10 i cout 正數個數 x endl cout 負數個數 y endl cout 零的...

C 基礎筆記 Day4

定義列舉要先寫乙個 enum 關鍵字,然後在 內新增一組符號標識,包括了該列舉型別可以擁有的合法值。enum season 放在公共區域 列舉內部的每個元素都關聯 對應著乙個整數值。預設第乙個元素對應整數 0,以後每個元素對應的整數都遞增 1。獲取列舉變數的整數值之前,必須先將它轉換為基本型別。en...