堀内涼平
    • 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

      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.
      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

    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.
    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
    # **解説** ## program0 ### #include<stdio.h> int main(void){return 0;} C言語で最初に書かれている文ですが、今はおまじないだと思っておいてください,この中にコードを書いていきます ```c #include<stdio.h> int main(void){ //ここにコードを書いていく return 0; } ``` ### printfとscanfの違いを理解しておきましょう ### printf printfは文字や数字を表示させることができます ```c printf("Hello World"); //これでHello Worldを表示させることができる ``` ### scanf scanfはキーボードで文字や数字を入力出来るようにすることができる ```c int a; scanf("%d",a); //これでキーボードから値を入力できるようになる ``` ## program2 ### if ここでは「**if文**」(「条件分岐の構文」)というものを扱います。これで条件に応じた処理をさせることができます。 例えば、もし、入力された数字が5以下であれば、ターミナルに「5以下」と表示し、その他(5より大きい値)であれば、「5より大きい」と表示するといった具合です。 このようにコードを書きます <img height=187 width=592 src="https://raw.githubusercontent.com/ryoto1038/c_flowchart/master/ifelse.png" alt="C言語" title="C言語"> #### program2のフローチャート(説明図) [ここ](https://github.com/ryoto1038/c_flowchart/blob/master/program2.png)にあります。 ## program3 ### while ここでは「**while文**」(「繰り返し処理」)というものを扱います。 これは同じ処理を真である限り続けるというものです。 このように書きます。 <img height=167 width=462 src="https://raw.githubusercontent.com/ryoto1038/c_flowchart/master/for_while.png" alt="Python" title="Python"> ここで注意していただきたいのですが、for文では、その回数分ループ変数に数値が代入されていきます。 ループ変数に代入される数値は、<b>0,1,2,3,4, ...という様に`0`から始まります。</b> <u>よって回数をnとすると、ループ変数に代入される値は、0~n-1となります。</u> #### program3のフローチャート [ここ](https://github.com/ryoto1038/c_flowchart/blob/master/program3.png)にあります。 ## program4_1 ### 無限ループ おそらくこれはゲームやスマホのバグで聞いたことがある言葉だと思いますが、意図的、あるいは偶発的によりプログラムが永遠に続くことを指します。 無限ループが発生するプログラムをprogram4_1.pyで扱っているので、プログラム下に書いてある説明書きをよく読んで、プログラムを実行してください。 #### program4_1のフローチャート [ここ](https://github.com/ryoto1038/c_flowchart/blob/master/program4_1.png)にあります。 ## program4_2 無限ループで使用できるものを紹介します。 ### while (常に真の時) これは条件を常に真の状態にさせて、**永遠にループ**を続けたい場合に使用します。 稼働し続ける必要のあるシステムなどで使用します。 ### if break ループ処理中にある条件に達した時に、そのループから**脱出**するものです。 ```c if break; ``` ### if continue ループ処理中にある条件に達した時に、条件分岐(そのループの最初)のところに戻ります。 ```c if continue; ``` #### スペース4つ問題 `if`と書いた後に`break`や`continue`を書く場合は、 改行 → Tabキー → (`break` or `continue`) 6 #### program4_2のフローチャート [ここ](https://github.com/ryoto1038/c_flowchart/blob/master/program4_2.png)にあります。 ## program5 #### program5のフローチャート [ここ](https://github.com/ryoto1038/c_flowchart/blob/master/program5.png)にあります。 ## program6 ### 配列 プログラミングをするにつれて、データ(数値、文字列)が多くなっていきます。 その都度変数を作って、値を格納していくのは大変効率が悪いです。 そこで役立つ**配列**という1つの変数にたくさんのデータ(値)をまとめられる機能を紹介します。 配列に代入された数値を**要素**といい、順番は0番目から順に始まっていきます。 例)a[3]という配列に順に1, `2`, `3`と代入していくと配列の0番目に1が、1番目に2が、2番目が3という様になります。 | a[0] | a[1] | a[2] | | -------- | -------- | -------- | | 1 | 2 | 3 | ## program7 ### 2次元の配列 ここでは配列の中に配列が入っている、2次元の配列というものを紹介します。 例)b[3][3]の配列を考えてみる。3行3列の配列で1行目1列はb[0][0]で以下のようになる。 | b[0][0] | b[0][1] | b[0][2] | | ----------- | ------- | ------- | | **b[1][0]** | **b[1][1]** | **b[1][2]** | | **b[2][0]** | **b[2][1]** | **b[2][2]** | 二重のfor文と組み合わせて表のように出力してみよう。 また、3次元以上の配列の作成も可能です。 ## program8 ここでは同じ処理を何回もさせたい場合に使える関数というものを紹介します。 ### 関数 値を渡されると、何かしらの計算をして、その値を返すもののことを関数といいます。 関数は以下のように書きます。 ```c void 関数名(仮変数1, 仮変数2, ....){ 処理 } int main (void){ 関数名(変数1,変数2,.....) } ``` これを見ただけだと理解し難いと思うので、まずはコードを書いてみて下さい。 ```c #include <stdio.h> void sum(int a,int b){ //足し算をして表示する関数 int c=0; c=a+b; printf("%d\n",c); //結果の表示 } int main(void){ int x=4,y=2; sum(x,y); return 0; } ``` 実行すると答えの6が出てくるはずです。 下から2行目を見てください。`sum(x,y)`というものがありますよね。 これが「**関数の呼び出し**」と呼ばれるもので、ここで関数の処理をさせています。()のなかに(計算させたい)引数を入れることで引数を使った計算をさせることができ、あらかじめ宣言した変数であれば、どのような変数でも関数の中に入れることができます。 上のプログラムでは`void sum(int a,int b)`の`int a`と`int b`はそれぞれ`a`と`x`, `b`と`y`が対応しており、上のように変数値に代入されている値が代入されます。 値が代入された後は関数の中に書かれて処理が行われます。 ## program9 ### 返り値 上では関数内の計算などの処理は関数内だけで完結しますが、今回扱う関数は計算結果、それに類する処理の結果を「**返り値**」として返してくれます。 返り値を用いたいときは次のように入力してください ```return 返り値;``` 先ほどと同じようにコードを書いてみましょう。(内容は同じもの) ```c #include <stdio.h> int sum(int a,int b){ //足し算の結果を返す関数 return a+b; } int main(void){ int x=4,y=2,c; c=sum(x,y); //関数の呼び出し printf("%d\n",c); return 0; } ``` 先ほどと同じように6が結果として出ます。 上の関数内の最後に`return`が書いてありますよね。このように関数の最後に`return`を書くことで、処理結果を返すことができます。その処理結果は上のように変数に代入することなどにより、使用することができます。 # program 10 ### 構造体 いくつかの変数をまとめて新しい変数を作る。 ```c struct date{ //date型の新しい変数を作る int id; char name[10]; } int main(void){ date a={19,Horiutchi} //date型のaという変数,定義と同時に初期化 } ``` ----- みなさんいかがでしたか? 以上がc言語の基本的な文法となっています。 c言語は一回生の秋学期で習います。実際の授業では同じ内容も扱いますがこれよりも少し難しことも範囲となります。ですが、基礎がしっかりとしていれば少しの応用が来ても何の問題もありません。しっかりと学習して秋学期の授業に臨みましょう。 何か質問があれば、slackやDMなど、どんな手段でもよいので質問してくださいね。 ----- 編集: Horiuchi,Mikawa,Inaba ----- 参照: 新・明解C言語 入門編

    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

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    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