跳到主要內容

計算導論與 C 語言基礎:第十週(C語言的基本成分 —— C程序的數組)

計算導論與 C 語言基礎:第九週(C語言的基本成分 ——  C程序的數組)


Part I : 一維數組初始化
注意:數組中的數字必須是個常數,若為 a[ i ] 也須定義 i 為一常數



若在main 中不定義,也可以在開頭使用 #define 的方式進行定義。   


若是開頭沒有對數組進行初始化,則在不同編譯器會自動給數組一組初始值,在VC編譯器中為下。
若是在數組中,括號中沒有數字,則在數組初始化時,會自動依照常數的定義直接從0開始編序。


若是沒有給數組完整的初始化,僅部分數組給予初始值,則剩下的部分則會自動以 0 於後補上。
若只給一個初始值,則全部都給相同的初始值=0
**但是切記==>若只有一個數組,卻有多個初始值,則不合理,無法成立。


二維數組
二為數組的基本定義方式: int a[3][4] 解釋如下
setw(3)表示每個數組佔三個byte
同樣,若是數組中的初始值給的不完整,則會在其他格補上0
有關於二維數組的初始化,參考下方,則可數組中的數字依照順序一一條列。




三維數組
三維數組的概念。




Part II :數組的作用
數組最經典的使用方法是在統計數值上面的方便。
習題如下:
結果
另外的方法:(提示)使用switch
更簡化:
經舔習題:為老師分學院和系,並數人數。
經典習題二:找出素數(質數)







留言

這個網誌中的熱門文章

【Quora 翻譯&整理】對於程式初學者嘗試解決問題的好網站推薦

原文出處: What are some suggested websites to solve programming problems for beginners? (2016/5/15) 此篇文章強調的是去參加project的那種網站推薦

第一章 電腦、網際網路與全球資訊網簡介

C++  How to Program 7/E 筆記 第一章 電腦、網際網路與全球資訊網簡介 學習目標 基本軟硬體觀念 物件技術觀念(類別、物件、屬性、行為、封裝、繼承) 程式語言的種類 典型的C++開發環境 業界標準物件導向素模語言——UML 沿革 網際網路、球球資訊網與Web 2.0現象的沿革 在Linux 的GNU C++ 與在Microsoft Visual C++環境中測試C++ 應用程式 *結構化程式設計(structured programming) *物件導向程式設計

【 Intro to Java Programming 】Lesson 1 : Introduction-5 (Algorithms)

This Notes is according to the udacity free course : Intro to Java Programming Lesson 1 : Introduction-5(Algorithms) Key Word : pseudocode Algorithms just like a doing things protocol+condition. Without protocol+condition, you can not make choice or do the decision. So if you want to buy car, you know the car speed and you don't consider the car price or the car condition, so it is your thought, it is the algorithm you buy a car. For computer, we give them the program ===>for them to do algorithm, but now we try to write done in Pseudocode. Pseudocode write in "spoken language" which help us to understand the problem so we can translate them into computer language ==>JAVA Code.org maybe it could help you have fun from learning code