kevin
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: c/c++變數與常數\ tage: c++程式設計實習 --- # 演算法(Alogrithm) ## 認識演算法 演算法(algorithm)就是一組用來解決特定問題的有限指令或步驟,我們可依循這些步驟來逐步解決問題或完成特定工作。演算法中的每一個步驟都必須非常明確,不可以模稜兩可。 ## 演算法的特性 演算法通常都有如下所示的5項特性。 1. 輸入(input):演算法中經常需要輸入資料。 2. 輸出(output):演算法至少要有一個以上的輸出資料。 3. 有限性(finiteness):演算法應該要在有限的處理步驟內得到結果。 4. 明確性(definiteness):每個步驟都必須明確,不能有模稜兩可的情況。 5. 有效性(effectiveness):每個步驟都必須是可實際做到或執行的。 ## 流程圖表示法 ![](https://i.imgur.com/s87UfYm.png) ![](https://i.imgur.com/wXgsAuq.png) ## 敘述表示法 1. 敘述表示法是使用虛擬碼,來表達演算法的處理步驟。 虛擬碼(pseudo code)是一種以簡潔扼要的文字,來設計程式邏輯的工具 2. 3. 範例 ![](https://i.imgur.com/bPlnJzI.png) :::success 程式執行簡易說明 ::: ![](https://i.imgur.com/lpPxbMY.png) :::success <font color='red'>**變數就是一塊記憶體空間**</font> ::: 1. 使用前必須先宣告: 從電腦取得一塊記憶體空間 2. 範例: 宣告一個可以儲存整數(integer)的記憶體空間 int x; // 記憶體空間的別名為x 3. 變數命名規則 - 第一個字元: $A\sim Z, a\sim z, \_$ 共 $53$個可用字元 - 第二個之後到結束字元: $A\sim Z, a\sim z, \_, 0\sim 9$ 4. 駝峰命名法: - 第一個單字的第一個字元為小寫 - 第二個單字的第二個字元為小寫,其餘為小寫 myAge, todayIsMyDay 5. 範例: 宣告一個能儲存學生英文成績的變數。 int engrade;` 6. ![](https://i.imgur.com/o5utmD5.png) ![](https://i.imgur.com/mfh7iaA.png) ![](https://i.imgur.com/iw6ZBkC.png) ![](https://i.imgur.com/LPINQur.png) ## 資料的種類:資料型別(Data Type) ### 整數: integer,沒有小數點的數字 1. chat: 字元型態的變數型態,可以表示1 byte大小的數字 - 範圍:$-128\sim 127$,共256$數字 - unsigend char:$0\sim255$,共$256數字 3. short:可表示$2$ byte大小的數字 4. int:可表示$4$ byte大小的數字 5. long:可表示$4$ byte大小的數字 6. long long:可表示$8$ byte大小的數字 :::info 以上的整數型態最前方加上unsingned修篩字,代表儲存的資料為正整數 ::: konichiwa tadaimasu ### 浮點數 :::success 有小數點的數字 ::: 1. float: 4 bytes, $-3.402e^{38} \sim 3.402e^{38}$。<font color='red'>**精確到小數點後第$6$位**</font> 2. double: 8 bytes,$-1.7976e^{308} \sim 1.7976e^{308}$。<font color='red'>**精確到小數點後第$15$位**</font> 3. long double: 8 bytes,$-1.7976e^{308} \sim 1.7976e^{308}$。<font color='red'>**精確到小數點後第$15$位**</font> 1. char:1byte的字元,可記錄一班的英文,數字或標點符號 2. wchar_t2bytes,可記錄中日韓文字 ### 字元 :::success 只要是可以從鍵盤輸入的都可以是字元,例如 Aa~Zz、0~9、?/,....等 ::: 1. char: 1 byte的字元,可記錄一般的英文、數字或標點符號 2. wchar_t: 2 bytes,可以記錄 中日韓文字 :::info ASCII code: https://en.wikipedia.org/wiki/Character_encoding ::: 1. 文字在電腦中也是以數值的方式來表示,為讓所有電腦系統都用一致的方式表示相同的字元, 2. 例如以65代表大寫A、97代表小寫a,這種以特定數值代表某個字元的方法就稱為編碼, 3. 目前資訊界一般所用的編碼為 美國標準資訊交換碼(American Standard Code for Information Interchange, ASCII) ![](https://i.imgur.com/h2p38SW.png) ### 布林 :::success 1: 代表ture(真),0:代表false(假) ::: 1. bool:1byte 2. 請注意在c語言中沒有true與false ## 設定變數的初始值 :::success 語法:<font color='red'>**資料型態 變數名稱=出值;**</font> ::: 1. 範例:宣告一個變數處存你的英文成績為60 'int engscore=60' 2. 範例:宣告一個變數處存你的英文成績為60分+你上課出席的分數(y) '''cpp=1 int y=50; int engscore=60+y; ''' 3. 由鍵盤輸入處存到變數中:<font color='red'>**要存入資料的變數必須先宣告,否則會產生錯誤**</font> '''cpp=1 int engscore; cin>>engscore; ''' # 常數 :::success 在程式中不能被改變諾嘗試去改變會產生錯誤**</font> ::: 1.使用const:<font color='red'>**constfloat PI=3.14159;**</font> 2.使用#define:<font color='bule'>**define PI3.14159**</font> ## 跳脫字元(\字元) :::success 格式:\+字元:例如單引號 雙引號等等 ::: 1. 顯示單引號'\'' 2. 顯示引號:'\"' 3. 自動輸入Enter(換行):""/n" # 用字元編碼指定字元 1. \+8進為數值:表示ASCII所代表的字元 '\144'代表a 2. \+或\X:x或X代表16進為數值,表示16進位值得ACLL,顯示ACLL所代表的字元 '\X61'代表a # 程式練習 cpp:;#include <iostream> using namespace std; int main() { /*測試資料型別所佔的記憶體空間大小:使用sizeof()*/ cout << "char 所占記憶體空間大小" <<sizeof(char)<<"byte\n"; cout <<"float所占記憶體大小:" <<sizeof(float)<<"bytes\n"; cout <<"long long 所占記憶體大小:" <<sizeof(unsigned long long)<<"bytes\n"; /*宣告變數測試 1. 整數型態的最大值+1=整數型態的最小值 2. 整數型態的最小值-1=整數型態的最大值 */ short x=32767; // x short 最大值 x=x+1; // x 變成 short 最小值 -32768 cout<<"short最大值+1="<<x<<",會變成short 最小值\n"; x=x*-1; // x 變成 short 最大值 32767 cout<<"short最大值-1="<<x<<",會變成short 最小值\n"; /*ASCII編碼*/ cout<<"輸出字元A; "<<'A' <<"(char)65" <<char(65)<<"\n"; //輸出ABCD...XYZ:(數字)轉為字元 x=65; for(int i=0; i<26; i++){ cout<<char(x+i); } cout<<"\n"; //輸出abc....xyz for(int i=0; i<26; i++){ cout<<char(x+i+32); } //將字元轉為ASCII(數字) cout<<"\n輸出A的ASCII code:"<<(int)'A'<<"\n"; cout<<"輸出A的ASCII code:"<<(int)'Z'<<"\n"; /*浮點數的精準度測試*/ float f =1.123456789; double d =1.123456789; cout.precision(16); cout<<"float value="<<f<<"\ndouble="<<d; /*布林測試*/ cout<<boolalpha; cout<<"\nture的值="<<int(true)<<t1的值為"<<"<<Bool(1); cout<<"\nflase的值="<<int(false)<<"t0的值為"<<<Bool(0) return 0; }

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully