C/C++ - 数组与指针

Similar documents
C/C++ - 函数

C/C++ - 文件IO

C/C++ 语言 - 循环

C/C++程序设计 - 字符串与格式化输入/输出

C/C++语言 - C/C++数据

untitled

untitled

C++ 程式設計

2-2

目 录 1 新 闻 政 策 追 踪 住 建 部 : 坚 持 因 城 施 策 完 善 房 地 产 宏 观 调 控 行 业 数 据 追 踪 限 购 政 策 落 地, 新 房 成 交 回 落 库 存 微 降, 一 线 去 化 表 现 稍

C/C++ - 字符输入输出和字符确认

投资高企 把握3G投资主题

宏观与策略研究

C C

专题研究.doc

C 1

信息管理部2003

C/C++语言 - 运算符、表达式和语句

産 産 産 産 産 爲 爲 爲 爲

2 图 1 新 民 科 技 2010 年 主 营 业 务 收 入 结 构 图 2 新 民 科 技 2010 年 主 营 业 务 毛 利 结 构 印 染 加 工 10.8% 其 他 4.8% 丝 织 品 17.2% 印 染 加 工 7.8% 其 他 4.4% 丝 织 品 19.1% 涤 纶 长 丝 6


宏碩-觀光指南coverX.ai

CC213

C 语言 第十讲 数组 张晓平 武汉大学数学与统计学院 2019 年 2 月 25 日

文章题目

行 业 研 究 证 券 行 业 周 报 1 1. 行 业 一 周 走 势 上 周 ( , 下 同 ) 沪 深 3 下 降.49%, 券 商 行 业 下 降 2.36%, 跑 输 大 盘 上 市 券 商 中 太 平 洋 上 涨 1.2%, 涨 幅 最 大 ; 广 发 证 券

C

(Microsoft PowerPoint [L So] \272C\251\312\252\375\266\353\251\312\252\315\257f [\254\333\256e\274\322\246\241])

香港中文大學校友會聯會陳震夏中學

PowerPoint Presentation

C/C++ - 字符串与字符串函数

新版 明解C言語入門編

1. 发 行 情 况 格 力 地 产 于 2014 年 12 月 25 日 发 行 9.8 亿 元 可 转 债 其 中, 原 股 东 优 先 配 售 亿 元 ( 万 手 ), 占 本 次 发 行 总 量 的 21.66% 网 上 向 一 般 社 会 公 众 投 资 者 发

二零零五年度报告框架稿

Microsoft Word - 第四章 資料分析

C

基金池周报

模 型 更 新 时 间 : 股 票 研 究 原 材 料 建 材 评 级 : 上 次 评 级 : 目 标 价 格 : 上 次 预 测 : 当 前 价 格 : 公 司 网 址 公 司 简 介 公 司 是 一 个 以

Microsoft Word - 01_FR_V3_Cover3_C.doc

Microsoft Word - 把时间当作朋友(2011第3版)3.0.b.06.doc

新・解きながら学ぶC言語

c_cpp

<4D F736F F D2047CEF7B7C920B9ABCBBED1D0BEBFB1A8B8E62E646F63>

出 版 : 會 員 通 訊 網 址 香 港 大 眾 攝 影 會 有 限 公 司 通 訊 地 址 : 香 港 郵 政 總 局 郵 箱 號 非 賣 品 只 供 會 閱 覽 HONG KONG CAMERA CLUB, LT

( CIP) /. :, ( ) ISBN TP CIP ( 2005) : : : : * : : 174 ( A ) : : ( 023) : ( 023)

Microsoft Word 年報.doc

untitled

<4D F736F F D20CAFDBEDDCFC2D6DCB9ABB2BC20CAD0B3A1B3E5B8DFC8D4D3D0D5F0B5B42E646F63>

---- TEL FAX II %

新・明解C言語入門編『索引』

<4D F736F F D20D6D0D2A9B2C4D0D0D2B5C9EEB6C8D1D0BEBFB1A8B8E62DD4A4BCC6BCD2D6D6D6D0D2A9B2C4BCDBB8F1BDABCFC2BDB5A3ACD3D0CDFBB3C9CEAA3133C4EACDB6D7CAD6F7CCE2>

<4D F736F F D D0CBB4EFB9FABCCA2D D B8FCD0C2B1A8B8E6B7B1CCE52E646F63>

nooog

untitled

Microsoft Word - Daily A.doc

<4D F736F F F696E74202D20BDD3CCECC1ABD2B6B1CCA3ACD3B3C8D5BAC9BBA8BAEC2E707074>

(i) (ii) (iii) (iv) 380,000 [ ] , , % % % 5.5% 6.5%


欢迎光临兴业证券 !

Title

Microsoft Word - Software sector_ _CN_.doc

(Microsoft PowerPoint - 03 \253\355\251w\245\315\262\ \301\277\270q.ppt)

二零零六年一月二十三日會議

厨房小知识(四)

妇女更年期保健.doc

小儿传染病防治(上)

<4D F736F F D B875B9B5A448ADFBBADEB27AA740B77EA4E2A5555FA95EAED6A641ADD75F2E646F63>

女性青春期保健(下).doc

避孕知识(下).doc

孕妇饮食调养(下).doc

禽畜饲料配制技术(一).doc

中老年保健必读(十一).doc

i

怎样使孩子更加聪明健康(七).doc

i

马太亨利完整圣经注释—雅歌

Sector — Subsector

(Microsoft Word \256\325\260\310\267|\304\263\254\366\277\375.doc)

Microsoft Word _ doc

1. 食 品 饮 料 本 周 观 点 食 品 饮 料 各 板 块 市 场 表 现 下 周 重 大 事 项 食 品 饮 料 公 司 盈 利 预 测 表 请 务 必 仔 细 阅 读 正 文 之 后 的 各 项 信 息 披 露 与 声 明 第

int *p int a 0x00C7 0x00C7 0x00C int I[2], *pi = &I[0]; pi++; char C[2], *pc = &C[0]; pc++; float F[2], *pf = &F[0]; pf++;

untitled

untitled

1 Project New Project 1 2 Windows 1 3 N C test Windows uv2 KEIL uvision2 1 2 New Project Ateml AT89C AT89C51 3 KEIL Demo C C File

目 录 1. 表 现 回 顾 与 行 业 观 点 行 业 表 现 :6 月 略 微 跑 输 大 市 行 业 观 点 :2H 相 对 收 益 乐 观 行 业 要 闻 与 公 司 动 态 行 业 要 闻 公 司 动 态


C/C++语言 - 分支结构

Title

<4D F736F F D20CDA8D0C5C9E8B1B8D6C6D4ECD2B5A3A A3A9A3BACEF6D6F7C1F7C9E8B1B82E646F63>

Microsoft Word - Daily A _CN_.doc

目 录 一 本 周 主 要 观 点... 3 二 造 纸 上 周 市 场 及 组 合 情 况 行 业 基 本 面 变 化 ) 产 品 价 格 : 成 品 纸 市 场 整 体 稳 定 ) 本 周 国 际 针 叶 浆 价 上 涨 阔 叶 浆 价 下

2013 C 1 # include <stdio.h> 2 int main ( void ) 3 { 4 int cases, a, b, i; 5 scanf ("%d", & cases ); 6 for (i = 0;i < cases ;i ++) 7 { 8 scanf ("%d %d

Microsoft Word _ doc

本 研 究 报 告 仅 通 过 邮 件 提 供 给 泰 信 基 金 管 理 有 限 公 司 泰 信 基 金 管 理 有 限 公 司 使 用 2 投 资 案 件 投 资 评 级 与 估 值 6 个 月 目 标 价 26 元, 首 次 评 级 给 与 买 入

东吴证券研究所


报告的主线及研究的侧重点

SB All Chinese_ITMU


C C C The Most Beautiful Language and Most Dangerous Language in the Programming World! C 2 C C C 4 C Project 30 C Project 3 60 Project 40

Transcription:

C/C++

Table of contents 1. 2. 3. 4. 5. 6. 7. 8. 1

float candy [ 365]; char code [12]; int states [50]; 2

int array [6] = {1, 2, 4, 6, 8, 10}; 3

// day_mon1.c: # include <stdio.h> # define MONTHS 12 int main ( void ) { int i; int days [ MONTHS ] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; for ( i = 0; i < MONTHS ; i ++) printf (" Month %2d has %2d days.\n", i+1, days [i]); return 0; } 4

Month 1 has 31 days. Month 2 has 28 days. Month 3 has 31 days. Month 4 has 30 days. Month 5 has 31 days. Month 6 has 30 days. Month 7 has 31 days. Month 8 has 31 days. Month 9 has 30 days. Month 10 has 31 days. Month 11 has 30 days. Month 12 has 31 days. 5

const // day_mon1_const.c: # include <stdio.h> # define MONTHS 12 int main ( void ) { const int days [ MONTHS ] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int i; for ( i = 0; i < MONTHS ; i ++) printf (" Month %2d has %2d days.\n", i+1, days [i]); return 0; } 6

const const 7

... // no_data.c: # include <stdio.h> # define SIZE 6 int main ( void ) { int no_data [ SIZE ]; int i; printf ("%2s%14 s\n", "i", " no_data [i]"); for ( i = 0; i < SIZE ; i ++) printf ("%2d%14 d\n", i, no_data [i]); return 0; } 8

... i no_data [i] 0 0 1 0 2 0 3 0 4 1606416376 5 32767 9

... 10

... // some_data.c: # include <stdio.h> # define SIZE 6 int main ( void ) { int some_ data [ SIZE ] = {11, 12}; int i; printf ("%2s%14 s\n", "i", " no_data [i]"); for ( i = 0; i < SIZE ; i ++) printf ("%2d%14 d\n", i, some_data [i]); return 0; } 11

... i no_data [i] 0 11 1 12 2 0 3 0 4 0 5 0 12

... 0 13

... 14

... # include <stdio.h> # define MONTHS 12 int main ( void ) { int i; const int days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; for ( i = 0; i < sizeof days / sizeof days [0]; i ++) printf (" Month %2d has %2d days.\n", i+1, days [i]); return 0; } 15

... sizeof days sizeof days[0] 16

C99 C int arr [6] = {0, 0, 0, 0, 0, 212}; 17

C99 C int arr [6] = {0, 0, 0, 0, 0, 212}; C99 int arr [6] = {[ 5] = 212}; // set arr [5] to 212 17

C99 // designate.c # include <stdio.h> # define MONTHS 12 int main ( void ) { int days [ MONTHS ] = {31, 28, [4] = 31, 30, 31, [1] = 29}; int i; for ( i = 0; i < MONTHS ; i ++) printf (" Month %2d has %2d days.\n", i+1, days [i]); return 0; } 18

C99 Month 1 has 31 days. Month 2 has 29 days. Month 3 has 0 days. Month 4 has 0 days. Month 5 has 31 days. Month 6 has 30 days. Month 7 has 31 days. Month 8 has 0 days. Month 9 has 0 days. Month 10 has 0 days. Month 11 has 0 days. Month 12 has 0 days. 19

C99 0 20

C 21

int main ( void ) { int arr1 [5] = {1, 2, 3, 4}; int arr2 [5]; } arr2 = arr1 ; // invalid arr2 [5] = arr1 [5]; // OK arr2 [5] = {1, 2, 3, 4}; // invalid 22

int arr [20]; 0 19 23

i // bounds.c # include <stdio.h> # define SIZE 4 int main ( void ) { int value1 = 14, value2 = 88; int arr [ SIZE ]; int i; printf (" value1 = %d, value2 = %d\n", value1, value2 ); for ( i = -1; i <= SIZE ; i ++) arr [ i] = 2 * i + 1; for ( i = -1; i < 7; i ++) printf ("%2d %d\n", i, arr [i]); printf (" value1 = %d, value2 = %d\n", 24

ii value1, value2 ); } return 0; 25

value1 = 14, value2 = 88-1 -1 0 1 1 3 2 5 3 7 4 9 5 32767 6 424094912 value1 = -1, value2 = 9 26

int n = 5; int m = 8; float a1 [5]; // OK float a2 [5*2 + 1]; // OK float a3[ sizeof ( int ) + 1]; // OK float a4 [ -1]; // Invalid float a5 [0]; // Invalid float a6 [2.5]; // Invalid float a7 [( int ) 2.5]; //OK, float to int float a8[n]; // C99 OK float a9[m]; // C99 OK 27

28

i /* rain. c -- finds yearly totals, yearly average, and monthly average for several years of rainfall data */ # include <stdio.h> # define MONTHS 12 // number of months in a year # define YEARS 5 // number of years of data int main ( void ) { // initializing rainfall data for 2000-2004 const float rain [ YEARS ][ MONTHS ] = { { 4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6 }, { 8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3 }, { 9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4 }, { 7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2 }, { 7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2 } }; int year, month ; float subtot, total ; 29

ii printf (" YEAR RAINFALL ( inches )\n"); for ( year = 0, total = 0; year < YEARS ; year ++) { // for each year, sum rainfall for each month for ( month = 0, subtot = 0; month < MONTHS ; month ++) subtot += rain [ year ][ month ]; printf ("%5d %15.1 f\n", 2000 + year, subtot ); total += subtot ; // total for all years } printf ("\ nthe yearly average is %.1 f inches.\n\n", total / YEARS ); printf (" MONTHLY AVERAGES :\n"); printf (" Jan Feb Mar Apr May Jun "); printf (" Jul Aug Sep Oct Nov Dec \ n"); for ( month = 0; month < MONTHS ; month ++) { // for each month, sum for ( year = 0, subtot =0; year < YEARS ; year ++) 30

iii subtot += rain [ year ][ month ]; printf (" %4.1 f", subtot / YEARS ); } printf ("\n"); } return 0; 31

YEAR RAINFALL ( inches ) 2000 32.4 2001 37.9 2002 49.8 2003 44.0 2004 32.9 The yearly average is 39.4 inches. MONTHLY AVERAGES : Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 7.3 7.3 4.9 3.0 2.3 0.6 1.2 0.3 0.5 1.7 3.6 6.7 32

sometype ar1 [5] = { val1, val2, val3, val4, val5 }; 33

rain[5][12] 5 12 float float 5 34

const float rain [ YEARS ][ MONTHS ] = { {4.3,4.3,4.3,3.0,2.0,1.2,0.2,0.2,0.4,2.4,3.5,6.6}, {8.5,8.2,1.2,1.6,2.4,0.0,5.2,0.9,0.3,0.9,1.4,7.3}, {9.1,8.5,6.7,4.3,2.1,0.8,0.2,0.2,1.1,2.3,6.1,8.4}, {7.2,9.9,8.4,3.3,1.2,0.8,0.4,0.0,0.6,1.7,4.3,6.2}, {7.6,5.6,3.8,2.8,3.8,0.2,0.0,0.0,0.0,1.3,2.6,5.2} }; 35

5 10 10 0 12 36

0 37

int box [10][20][30]; box 10 20 20 30 38

39

40

array array == & array [0]; 40

i // pnt_ add. c -- pointer addition # include <stdio.h> # define SIZE 4 int main ( void ) { short dates [ SIZE ]; short * pti ; short index ; double bills [ SIZE ]; double * ptf ; pti = dates ; // assign address of array to pointer ptf = bills ; 41

ii printf (" %23 s %14 s\n", " short ", " double "); for ( index = 0; index < SIZE ; index ++) printf (" pointers + %d: %14 p %14 p\n", index, pti + index, ptf + index ); } return 0; 42

short double pointers + 0: 0 x7fff5fbff7d0 0 x7fff5fbff7b0 pointers + 1: 0 x7fff5fbff7d2 0 x7fff5fbff7b8 pointers + 2: 0 x7fff5fbff7d4 0 x7fff5fbff7c0 pointers + 3: 0 x7fff5fbff7d6 0 x7fff5fbff7c8 43

C 1 44

* 1 45

dates + 2 == & dates [2]; // *( dates + 2) == dates [2]; // 46

C array[n] *(array + n) array n 47

*(dates+2) *dates+2 * + (*dates)+2 *( dates + 2) // dates * dates + 2 // dates 2 48

/* day_ mon3. c -- uses pointer notation */ # include <stdio.h> # define MONTHS 12 int main ( void ) { int index ; int days [ MONTHS ] = {31,28,31,30,31,30, 31,31,30,31,30,31}; } for ( index = 0; index < MONTHS ; index ++) printf (" Month %2d has %d days.\n", index +1, *( days + index )); // same as days [ index ] return 0; 49

50

int sum ( int * ar) { int i; int total = 0; for ( i = 0; i < 10; i ++) total += ar[i]; } return total ; 51

int sum ( int * ar) { int i; int total = 0; for ( i = 0; i < 10; i ++) total += ar[i]; } return total ; 10 51

int sum ( int * ar, int n) { int i; int total = 0; for (i = 0; i < n; i ++) total += ar[i]; } return total ; 52

int sum ( int * ar, int n) { int i; int total = 0; for (i = 0; i < n; i ++) total += ar[i]; } return total ; 52

int sum ( int * ar, int n); int sum ( int *, int ); int sum ( int ar [], int n); int sum ( int [], int ); 53

int sum ( int * ar, int n) {... } int sum ( int ar [], int n) {... } 54

55

i // sum_ arr1. c -- sums the elements of an array # include <stdio.h> # define SIZE 10 int sum ( int ar [], int n); int main ( void ) { int marbles [ SIZE ] = {20,10, 5,39, 4, 16,19,26,31,20}; long answer ; answer = sum ( marbles, SIZE ); printf (" The total number of marbles is % ld.\ n", answer ); 56

ii } printf (" The size of marbles is %lu bytes.\n", sizeof marbles ); return 0; int sum ( int *ar, int n) { int i; int total = 0; for (i = 0; i < n; i ++) total += ar[i]; printf (" The size of ar is %lu bytes.\n", sizeof ar); 57

iii } return total ; 58

The size of ar is 8 bytes. The total number of marbles is 190. The size of marbles is 40 bytes. 59

The size of ar is 8 bytes. The total number of marbles is 190. The size of marbles is 40 bytes. marbles 40 marbles 10 int 4 ar 8 ar marbles 59

sum() 60

61

i // sum_ arr2. c -- sums the elements of an array # include <stdio.h> # define SIZE 10 int sump ( int * start, int * end ); int main ( void ) { int marbles [ SIZE ] = {20,10,5,39,4, 16,19,26,31,20}; long answer ; answer = sump ( marbles, marbles + SIZE ); printf (" The total number of marbles is % ld.\ n", answer ); return 0; } 62

ii /* use pointer arithmetic */ int sump ( int * start, int * end ) { int total = 0; while ( start < end ) { total += * start ; start ++; } return total ; } 63

start marbles total += *start total start++ start 1 64

sump() while ( start < end ) end end 65

sump() while ( start < end ) end end C 65

sump() while ( start < end ) end end C answer = sump ( marbles, marbles + SIZE ); 65

end answer = sump ( marbles, marbles + SIZE - 1); 66

end answer = sump ( marbles, marbles + SIZE - 1); C marbles+size marbles[size] 66

total += * start ; start ++; total += * start ++; * ++ ++ start *start 1 1 67

total += * start ; start ++; total += * start ++; * ++ ++ start *start 1 1 total += *start++ total 1 67

total += * start ; start ++; total += * start ++; * ++ ++ start *start 1 1 total += *start++ total 1 total += *++start 1 total 67

total += * start ; start ++; total += * start ++; * ++ ++ start *start 1 1 total += *start++ total 1 total += *++start 1 total (*start)++ start 1 1 67

i // order. c -- precedence in pointer operations # include <stdio.h> int data [2] = {100, 200}; int moredata [2] = {300, 400}; int main ( void ) { int * p1, * p2, * p3; p1 = p2 = data ; p3 = moredata ; printf ("*p1 = %d, *p2 = %d, *p3 = %d\n", *p1, *p2, *p3); 68

ii printf ("*p1 ++ = %d, *++ p2 = %d, (* p3)++ = %d\n ", *p1 ++, *++ p2, (* p3)++) ; printf ("*p1 = %d, *p2 = %d, *p3 = %d\n", *p1, *p2, *p3); } return 0; 69

*p1 = 100, *p2 = 100, *p3 = 300 *p1 ++ = 100, *++ p2 = 200, (* p3)++ = 300 *p1 = 200, *p2 = 200, *p3 = 301 70

C ar[i] *( ar+i) ar ar ar++ 71

int urn [5] = {100,200,300,400,500}; int * ptr, * ptr1, * ptr2 ; 72

1 (assignment) & ptr1 = urn ; ptr2 = & urn [2]; double int 73

2 ( dereferencing) * 3 & 74

4 ptr = urn ptr + 4 &urn[4] 5 ptr = &urn[2] ptr++ ptr urn[3] 75

6 ptr = &urn[4] ptr - 2 &urn[2] 7 ptr = &urn[4] ptr-- ptr urn[3] 76

8 ptr1 = &urn[2], ptr2 = &urn[4] ptr2 - ptr1 2 9 77

i // ptr_ops. c -- pointer operations # include <stdio.h> int main ( void ) { int urn [5] = {100,200,300,400,500}; int * ptr1, * ptr2, * ptr3 ; ptr1 = urn ; ptr2 = & urn [2]; printf (" pointer value, dereferenced pointer, pointer address :\n"); printf (" ptr1 = %p, * ptr1 =%d, & ptr1 = %p\n", ptr1, *ptr1, & ptr1 ); ptr3 = ptr1 + 4; 78

ii printf ("\ nadding an int to a pointer :\n"); printf (" ptr1 + 4 = %p, *( ptr4 + 3) = %d\n", ptr1 + 4, *( ptr1 + 3)); ptr1 ++; printf ("\ nvalues after ptr1 ++:\ n"); printf (" ptr1 = %p, * ptr1 =%d, & ptr1 = %p\n", ptr1, *ptr1, & ptr1 ); ptr2 - -; printf ("\ nvalues after -- ptr2 :\n"); printf (" ptr2 = %p, * ptr2 = %d, & ptr2 = %p\n", ptr2, *ptr2, & ptr2 ); -- ptr1 ; ++ ptr2 ; 79

iii printf ("\ npointers reset to original values :\ n"); printf (" ptr1 = %p, ptr2 = %p\n", ptr1, ptr2 ); printf ("\ nsubtracting one pointer from another :\ n"); printf (" ptr2 = %p, ptr1 = %p, ptr2 - ptr1 = %ld\n", ptr2, ptr1, ptr2 - ptr1 ); printf ("\ nsubtracting an int from a pointer :\ n"); printf (" ptr3 = %p, ptr3-2 = %p\n", ptr3, ptr3-2); } return 0; 80

i pointer value, dereferenced pointer, pointer address : ptr1 = 0 x7fff5fbff7c0, * ptr1 =100, & ptr1 = 0 x7fff5fbff7b0 adding an int to a pointer : ptr1 + 4 = 0 x7fff5fbff7d0, *( ptr4 + 3) = 400 values after ptr1 ++: ptr1 = 0 x7fff5fbff7c4, * ptr1 =200, & ptr1 = 0 x7fff5fbff7b0 values after -- ptr2 : ptr2 = 0 x7fff5fbff7c4, * ptr2 = 200, & ptr2 = 0 x7fff5fbff7a8 Pointers reset to original values : 81

ii ptr1 = 0 x7fff5fbff7c0, ptr2 = 0 x7fff5fbff7c8 subtracting one pointer from another : ptr2 = 0 x7fff5fbff7c8, ptr1 = 0 x7fff5fbff7c0, ptr2 - ptr1 = 2 subtracting an int from a pointer : ptr3 = 0 x7fff5fbff7d0, ptr3-2 = 0 x7fff5fbff7c8 82

C 83

int *pt; // *pt = 5; // 84

int *pt; // *pt = 5; // *pt = 5 5 pt pt 5 84

85

malloc() 85

int urn [3]; int * ptr1, * ptr2 ; ptr1++; ptr2 = ptr1 + 2; ptr2 = urn + 1; urn++; ptr2 = ptr2 + ptr1; ptr2 = urn * ptr1; 86

int int int 87

88

89

void add_ to ( double arr [], int n, double val ) { int i; for (i = 0; i < n; i ++) arr [i] += val ; } 90

void add_ to ( double arr [], int n, double val ) { int i; for (i = 0; i < n; i ++) arr [i] += val ; } 90

ar arr[i]++ 1 void sum ( int arr [], int n) { int i; int sum = 0; for (i = 0; i < n; i ++) sum += arr [i ]++; } 91

const ANSI C const void sum ( const int arr [], int n); // void sum ( const int arr [], int n) // { int i; int sum = 0; for (i = 0; i < n; i ++) sum += arr [i]; } arr arr[i]++ 92

const const const const const 93

const i /* arf.c -- array functions */ # include <stdio.h> # define SIZE 5 void show_ array ( const double ar [], int n); void mult_ array ( double ar [], int n, double mult ) ; int main ( void ) { double dip [ SIZE ] = {20.0, 17.66, 8.2, 15.3, 22.22}; printf (" The original dip array :\n"); show_array (dip, SIZE ); mult_array (dip, SIZE, 2.5) ; 94

const ii printf (" The dip array after calling mult_ array :\n"); show_array (dip, SIZE ); } return 0; /* displays array contents */ void show_ array ( const double ar [], int n) { int i; for (i = 0; i < n; i ++) printf (" %8.3 f ", ar[i]); putchar ( \n ); } 95

const iii /* multiplies each array member by the same multiplier */ void mult_ array ( double ar [], int n, double mult ) { int i; for (i = 0; i < n; i ++) ar[i] *= mult ; } 96

const The original dip array : 20. 000 17. 660 8. 200 15. 300 22. 220 The dip array after calling mult_ array (): 50. 000 44. 150 20. 500 38. 250 55. 550 97

const 1. const const double PI = 3. 1415926; #define # define PI 3. 1415926 98

const 2. const 99

const const # define MONTHS 12... const int days [ MONTHS ] = {31,28,31,30,31,30, 31,31,30,31,30,31};... days [9] = 44; // 100

const double rates [4] = {8.9, 10.1, 9.4, 3. 2}; const double * pd = rates ; //pd *pd = 29.89; // pd [2] = 222.22; // rates [0] = 99.99; // rates pd ++; // pd rates[1] 101

const void show_ array ( const double * ar, int n); 102

const const (a) double rates [4] = {8.9, 10.1, 9.4, 3. 2}; const double locked [4] = {0.8, 0.7, 0.2, 0.3}; const double * pc = rates ; // pc = locked ; // pc = & rates [3]; // 103

const const (b) double rates [4] = {8.9, 10.1, 9.4, 3. 2}; const double locked [4] = {0.8, 0.7, 0.2, 0.3}; double * pnc = rates ; // pnc = locked ; // pnc = & rates [3]; // 104

const show_array show_array ( rates, 4); // show_array ( locked, 4); // mult_array mult_array ( rates, 4); // mult_array ( locked, 4); // const const 105

const 3. const double rates [4] = {8.9, 10.1, 9.4, 3. 2}; double const * pc = rates ; //pc pc = & rates [3]; // *pc = 2.2; // rates[0] 106

const 4. const double rates [4] = {8.9, 10.1, 9.4, 3. 2}; const double const * pc = rates ; pc = & rates [3]; // *pc = 2.2; // 107

108

int zippo [4][2]; // zippo zippo int zippo int 109

zippo zippo == &zippo[0] zippo[0] int zippo[0] == &zippo[0][0] zippo zippo[0] zippo == zippo[0] 110

1 zippo zipp[0] zippo int zipp[0] int zippo+1 zippo[0]+1 111

zippo[0] zippo[0][0] *( zippo [0]) == zippo [0][0] int 112

zippo zippo[0] * zippo == zippo [0] zippo [0] == & zippo [0][0] * zippo == & zippo [0][0] *& zippo [0][0] == zippo [0][0] ** zippo == zippo [0][0] 113

zippo 114

i /* zippo1.c -- zippo info */ # include <stdio.h> int main ( void ) { int zippo [4][2] = { {2,4}, {6,8}, {1,3}, {5,7} }; printf (" zippo = %p, zippo +1 = % p\ n", zippo, zippo +1) ; printf (" zippo [0] = %p, zippo [0]+1 = %p\n", zippo [0], zippo [0]+1) ; printf (" * zippo = %p, * zippo +1 = %p\n", * zippo, * zippo +1) ; printf (" zippo [0][0] = %d\n", zippo [0][0]) ; printf (" * zippo [0] = %d\n", * zippo [0]) ; 115

ii printf ("** zippo = %d\n", ** zippo ); printf (" zippo [2][1] = %d\n", zippo [2][1]) ; printf (" *(*( zippo +2) + 1) = %d\n", *(*( zippo +2) + 1) ); } return 0; 116

zippo = 5 fbff7b0, zippo + 1 = 5 fbff7b8 zippo [0] = 5 fbff7b0, zippo [0] + 1 = 5 fbff7b4 * zippo = 5 fbff7b0, * zippo + 1 = 5 fbff7b4 zippo [0][0] = 2 * zippo [0] = 2 ** zippo = 2 zippo [2][1] = 3 *(*( zippo +2) + 1) = 3 zippo 1 8 zippo[0] 1 4 117

1: *(*(zippo+2)+1) zippo zippo+2 *(zippo+2) *(zippo+2)+1 *(*(zippo+2)+1) zippo[0] zippo[2] zippo[2] zippo[2] zippo[2] 2 zippo[2] 2 118

zippo[2][1] 119

pz 120

int (* pz) [2]; pz int 121

int * pax [2]; pax pax * pax int pax int int 122

i /* zippo2.c -- zippo info */ # include <stdio.h> int main ( void ) { int zippo [4][2] = { {2,4}, {6,8}, {1,3}, {5,7} }; int (* pz) [2]; pz = zippo ; printf (" pz = %p, pz + 1 = %p\n", pz, pz + 1); printf (" pz [0] = %p, pz [0] + 1 = %p\n", pz [0], pz [0] + 1); printf (" *pz = %p, *pz + 1 = %p\n", *pz, *pz + 1); printf (" pz [0][0] = %d\n", pz [0][0]) ; 123

ii printf (" *pz [0] = %d\n", *pz [0]) ; printf ("** pz = %d\n", ** pz); printf (" pz [2][1] = %d\n", pz [2][1]) ; printf (" *(*( pz +2) + 1) = %d\n", *(*( pz +2) + 1)); } return 0; 124

pz = 5 fbff7b0, pz + 1 = 5 fbff7b8 pz [0] = 5 fbff7b0, pz [0] + 1 = 5 fbff7b4 *pz = 5 fbff7b0, *pz + 1 = 5 fbff7b4 pz [0][0] = 2 *pz [0] = 2 ** pz = 2 pz [2][1] = 3 *(*( pz +2) + 1) = 3 125

pz pz[2][1] zippo [m][n] == *(*( zippo +m)+n) pz[m][n] == *(*( pz+m)+n) 126

int double int n = 5; double x; int * pi = &n; double * pd = &x; x = n; // pd = pi; // 127

int * pt; int (* pa) [3]; int ar1 [2][3]; int ar2 [3][2]; int ** p2; // pt = & ar1 [0][0]; // int pt = ar1 [0]; // int pa = ar1 ; // int[3] p2 = &pt; // int * 128

pt = ar1 ; // pa = ar2 ; // *p2 = ar2 [0]; // int p2 = ar2 ; // pt int ar1 3 int pa 3 int ar2 2 int p2 int ar2 2 int *p2 int ar2[0] ar2[0] ar2[0][0] ar2[0][0] int 129

int * p1; const int * p2; const int ** pp2 ; p1 = p2; // const const p2 = p1; // const const pp2 = &p1; // const const const const const const const 130

int * p1; const int ** pp2 ; const int n = 13; pp2 = &p1; // * pp2 = &n; // const p1 n *p1 = 10; // const n 131

132

133

i // array2d. c -- functions for 2d arrays # include <stdio.h> # define ROWS 3 # define COLS 4 void sum_rows ( int ar [][ COLS ], int rows ); void sum_cols ( int [][ COLS ], int ); int sum2d ( int (* ar)[ COLS ], int rows ); int main ( void ) { int junk [ ROWS ][ COLS ] = { {2,4,6,8}, {3,5,7,9}, {12,10,8,6} }; 134

ii sum_rows (junk, ROWS ); sum_cols (junk, ROWS ); printf (" Sum of all elements = %d\n", sum2d (junk, ROWS )); } return 0; void sum_rows ( int ar [][ COLS ], int rows ) { int r, c, tot ; for ( r = 0; r < rows ; r ++) { tot = 0; for ( c = 0; c < COLS ; c ++) 135

iii } } tot += ar[r][c]; printf (" row %d: sum = %d\n", r, tot ); void sum_cols ( int ar [][ COLS ], int rows ) { int r, c, tot ; for ( c = 0; c < COLS ; c ++) { tot = 0; for ( r = 0; r < rows ; r ++) tot += ar[r][c]; printf (" col %d: sum = %d\n", c, tot ); } 136

iv } int sum2d ( int ar [][ COLS ], int rows ) { int r, c; int tot = 0; } for ( r = 0; r < rows ; r ++) for ( c = 0; c < COLS ; c ++) tot += ar[r][c]; return tot ; 137

row 0: sum = 20 row 1: sum = 24 row 2: sum = 36 col 0: sum = 17 col 1: sum = 19 col 2: sum = 21 col 3: sum = 23 Sum of all elements = 80 138

ar 4 int 4 139

int sum2 ( int ar [][], int rows ); ar[1] ar+1 ar 140

int sum2 ( int ar [][], int rows ); ar[1] ar+1 ar int sum2 ( int ar [][4], int rows ); ar 4 int ar+1 16 140

int sum2 ( int ar [3][4], int rows ); 3 141

n int sum4d ( int ar [][4][5][6], int rows ); 142

n int sum4d ( int ar [][4][5][6], int rows ); int sum4d ( int (* ar) [4][5][6], int rows ); ar 4 5 6 int 142

# define COLS 4 int sum2d ( int ar [][ COLS ], int rows ) { int r; int c; int tot = 0; for ( r = 0; r < rows ; r ++) for ( c = 0; c < COLS ; c ++) tot += ar[r][c]; return tot ; } 143

int ar1 [5][4]; int ar2 [100][4]; int ar3 [2][4]; tot = sum2d (ar1, 5); tot = sum2d (ar2, 100) ; tot = sum2d (ar3, 2); 144

6 5 COLS 5 COLS 145

146

FORTRAN FORTRAN FORTRAN C FORTRAN FORTRAN 147

C99 (VLA) 148

C99 (VLA) int m = 4; int n = 5; double array [m][n]; 148

int 149

1 int sum2d ( int rows, int cols, int ar[ rows ][ cols ]); rows cols ar int sum2d ( int ar[ rows ][ cols ], int rows, int cols ); int sum2d (int, int, int ar [*][*]) ; 150

2 int sum2d ( int rows, int cols, int ar[ rows ][ cols ]) { int r; int c; int tot = 0; for ( r = 0; r < rows ; r ++) for ( c = 0; c < cols ; c ++) tot += ar[r][c]; return tot ; } 151

i // vararr2d. c -- functions using VLAs # include <stdio.h> # define ROWS 3 # define COLS 4 int sum2d ( int rows, int cols, int ar[ rows ][ cols ]); int main ( void ) { int i, j; int rs = 3; int cs = 10; int junk [ ROWS ][ COLS ] = { {2,4,6,8}, {3,5,7,9}, {12,10,8,6} }; 152

ii int morejunk [ ROWS -1][ COLS +2] = { {20,30,40,50,60,70}, {5,6,7,8,9,10} }; int varr [rs ][ cs ]; // VLA for ( i = 0; i < rs; i ++) for ( j = 0; j < cs; j ++) varr [i][j] = i * j + j; printf ("3x5 array \n"); printf (" Sum of all elements = % d\ n", sum2d (ROWS, COLS, junk )); printf ("2x6 array \n"); printf (" Sum of all elements = % d\ n", 153

iii } sum2d (ROWS -1, COLS +2, morejunk )); printf ("3 x10 VLA \n"); printf (" Sum of all elements = % d\ n", sum2d (rs, cs, varr )); return 0; // function with a VLA parameter int sum2d ( int rows, int cols, int ar[ rows ][ cols ]) { int r, c; int tot = 0; for ( r = 0; r < rows ; r ++) for ( c = 0; c < cols ; c ++) tot += ar[r][c]; return tot ; } 154

3x5 array Sum of all elements = 80 2x6 array Sum of all elements = 315 3 x10 VLA Sum of all elements = 270 155

156

{ } int thing [10][6]; twoset (10, 6, thing );... void twoset ( int n, int m, int ar[n][m]) //ar m int { int temp [n][m]; //temp nxm int temp [0][0] = 2; // temp 2 ar [0][0] = 2; // thing[0][0] 2 } 157

int float 158

159

160

1 161

i // ex01.c # include <stdio.h> void swap ( double * a, double * b); void sort ( double arr [], int n); void print_ arr ( double arr [], int n); int main ( void ) { double arr [7] = {1.1, 2.2, 7.7, 4.4, 5.5, 3.3, 6.6}; print_arr (arr, 7); sort (arr, 7); print_arr (arr, 7); return 0; } void swap ( double * a, double * b) 162

ii { } double temp ; temp = *a; *a = *b; *b = temp ; void sort ( double arr [], int n) { int i, j, pos ; for (i = 0; i < n;i ++) { pos = i; for (j = i +1; j < n; j ++) { if(arr [j] < arr [ pos ]) pos = j; } 163

iii } } if ( pos!= i) swap (& arr [i], & arr [ pos ]); void print_ arr ( double arr [], int n) { int i; for ( i = 0; i < n; i ++) printf (" %6.2 f ", arr [i]); putchar ( \n ); } 164

2 double double source [5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1 [5], target2 [ 5]; copy_arr ( source, target1, 5); copy_ptr ( source, target2, 5); 165

i // ex02.c # include <stdio.h> # define SIZE 5 void copy_ arr ( double source [], double target [], int n) ; void copy_ ptr ( double * source, double * target, int n) ; void print_ arr ( double arr [], int n); int main ( void ) { double source [5] = {1.1, 2.2, 3.3, 4.4, 5.5}; double target1 [5], target2 [5]; copy_arr ( source, target1, SIZE ); copy_ptr ( source, target2, SIZE ); print_arr ( source, SIZE ); 166

ii } print_arr ( target1, SIZE ); print_arr ( target2, SIZE ); return 0; void copy_ arr ( double source [], double target [], int n) { int i; for ( i = 0; i < n; i ++) target [i] = source [i]; } void copy_ ptr ( double * source, double * target, int n) { double * ptr1 = source ; double * ptr2 = target ; 167

iii } while ( ptr1 < source + n) * ptr2 ++ = * ptr1 ++; void print_ arr ( double arr [], int n) { int i; for ( i = 0; i < n; i ++) printf (" %6.2 f ", arr [i]); putchar ( \n ); } 168

3 7 3 5 3 169

i // ex03.c # include <stdio.h> void copy_ arr ( double source [], double target [], int n) ; void print_ arr ( double arr [], int n); int main ( void ) { double source [7] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7}; double target [3]; copy_arr ( source +2, target, 3); print_arr ( source, 7); print_arr ( target, 3); return 0; } 170

ii void copy_ arr ( double source [], double target [], int n) { int i; for ( i = 0; i < n; i ++) target [i] = source [i]; } void print_ arr ( double arr [], int n) { int i; for ( i = 0; i < n; i ++) printf (" %6.2 f ", arr [i]); putchar ( \n ); } 171

4 double 172

i // ex04.c # include <stdio.h> void max_ arr1d ( double * arr, int n, double * max, int * index ); int main ( void ) { double array [4] = {2.0, -1.0,5.0,5.0}; double max ; int index ; max_arr1d ( array, 4, &max, & index ); printf (" the maximum value of array is % f " " which is located at %d- th element.\ n", max, index +1) ; return 0; } 173

ii void max_ arr1d ( double * arr, int n, double * max, int * index ) { int i; * max = arr [0]; * index = 0; for (i = 1; i < n; i ++) { if (* max < arr [i]) { * max = arr [i]; * index = i; } } } 174

5 175

i // ex05.c # include <stdio.h> void sum_ arr1d ( int * arr1, int * arr2, int * arr3, int n); void print_ arr1d ( int arr1d [], int n); int main ( void ) { int arr1 [4] = {2,4,5,8}; int arr2 [4] = {1,0,4,6}; int arr3 [4]; sum_arr1d (arr1, arr2, arr3, 4); print_arr1d (arr1, 4); print_arr1d (arr2, 4); print_arr1d (arr3, 4); return 0; 176

ii } void sum_ arr1d ( int * arr1, int * arr2, int * arr3, int n) { int i; for ( i = 0; i < n; i ++) arr3 [i] = arr1 [i] + arr2 [i]; } void print_ arr1d ( int arr1d [], int n) { int i; for ( i = 0; i < n; i ++) printf ("%3d ", arr1d [i]); putchar ( \n ); 177

iii } 178

6 u = (a 1,a 2,a 3 ) T, v = (b 1,b 2,b 3 ) T u v = a 1 b 1 +a 2 b 2 +a 3 b 3 u v = i j k a 1 a 2 a 3 b 1 b 2 b 3 = (a 2 b 3 a 3 b 2,a 3 b 1 a 1 b 3,a 1 b 2 a 2 b 1 ) T. 179

7 5 double 1. 3 5 2. 3. 4. 15 5. 180

// ex07.h # include <stdio.h> # define COLS 5 # define ROWS 3 void input_ array2d ( double arr2d [][ COLS ], int row ); void print_ array1d ( double arr1d [], int n); void print_ array2d ( double arr2d [][ COLS ], int row ); double aver_ array1d ( double * arr1d, int n); void aver_ array2d_ row ( double arr2d [][ COLS ], int row, double average []) ; double aver_ array2d ( double arr2d [][ COLS ], int row ); double max_ array2d ( double arr2d [][ COLS ], int row ); 181

i // ex07.c # include " ex07.h" int main ( void ) { double arr2d [ ROWS ][ COLS ]; double average_ row [ ROWS ]; double average, max ; printf (" Please input 3 sets of five double numbers each.\n"); input_array2d ( arr2d, ROWS ); printf (" The array is :\n"); print_array2d ( arr2d, ROWS ); aver_array2d_row ( arr2d, ROWS, average_row ); printf (" average of each row :\n"); 182

ii print_ array1d ( average_row, ROWS ); average = aver_ array2d ( arr2d, ROWS ); printf (" average of arr2d is %5.2 f\ n", average ); max = max_array2d ( arr2d, ROWS ); printf (" max of arr2d is %5.2 f\n", max ); } return 0; void input_ array2d ( double arr2d [][ COLS ], int row ) { int r, c; for ( r = 0; r < row ; r ++) for ( c = 0; c < COLS ; c ++) 183

iii } scanf ("%lf", & arr2d [r][c]); void print_ array1d ( double arr1d [], int n) { int i; for ( i = 0; i < n; i ++) printf (" %8.2 f", arr1d [i]); putchar ( \n ); } void print_ array2d ( double arr2d [][ COLS ], int row ) { int r; for ( r = 0; r < row ; r ++) print_array1d ( arr2d [r], COLS ); 184

iv } double aver_ array1d ( double * arr1d, int n) { int i; double total = 0.0; for ( i = 0; i < n; i ++) total += arr1d [ i]; return total /( double ) n; } void aver_ array2d_ row ( double arr2d [][ COLS ], int row, double average []) { int i; for ( i = 0; i < row ; i ++) 185

v } average [i] = aver_array1d ( arr2d [i], COLS ); double aver_ array2d ( double arr2d [][ COLS ], int row ) { int i, j; double total = 0.0; for ( i = 0; i < row ; i ++) for ( j = 0; j < COLS ; j ++) total += arr2d [i][j]; return total /( double ) ( row * COLS ); } double max_ array2d ( double arr2d [][ COLS ], int row ) { int i, j; 186

vi } double max = arr2d [0][0]; for ( i = 0; i < row ; i ++) for ( j = 0; j < COLS ; j ++) if ( max < arr2d [i][j]) max = arr2d [i][j]; return max ; 187

8 188

// ex08.h # include <stdio.h> void input_ array2d ( int row, int col, double arr2d [ row ][ col ]); void print_ array1d ( double arr1d [], int n); void print_ array2d ( int row, int col, double arr2d [ row ][ col ]); double aver_ array1d ( double * arr1d, int n); void aver_ array2d_ row ( int row, int col, double arr2d [ row ][ col ], double average []) ; double aver_ array2d ( int row, int col, double arr2d [ row ][ col ]); double max_ array2d ( int row, int col, double arr2d [ row ][ col ]); 189

i // ex08.c # include " ex08.h" int main ( void ) { int row = 3; int col = 5; double arr2d [ row ][ col ]; double average_ row [ row ]; double average, max ; printf (" Please input 3 sets of five double numbers each.\n"); input_array2d (row, col, arr2d ); printf (" The array is :\n"); print_array2d (row, col, arr2d ); aver_array2d_row (row, col, arr2d, average_row ); 190

ii printf (" average of each row :\n"); print_ array1d ( average_row, row ); average = aver_ array2d ( row, col, arr2d ); printf (" average of arr2d is %5.2 f\ n", average ); max = max_array2d (row, col, arr2d ); printf (" max of arr2d is %5.2 f\n", max ); } return 0; void input_ array2d ( int row, int col, double arr2d [ row ][ col ]) { 191

iii } int r, c; for ( r = 0; r < row ; r ++) for ( c = 0; c < col ; c ++) scanf ("%lf", & arr2d [r][c]); void print_ array2d ( int row, int col, double arr2d [ row ][ col ]) { int r; for ( r = 0; r < row ; r ++) print_array1d ( arr2d [r], col ); } void print_ array1d ( double arr1d [], int n) { 192

iv } int i; for ( i = 0; i < n; i ++) printf (" %8.2 f", arr1d [i]); putchar ( \n ); double aver_ array1d ( double * arr1d, int n) { int i; double total = 0.0; for ( i = 0; i < n; i ++) total += arr1d [ i]; return total /( double ) n; } 193

v void aver_ array2d_ row ( int row, int col, double arr2d [ row ][ col ], double average []) { int i; for ( i = 0; i < row ; i ++) average [i] = aver_array1d ( arr2d [i], col ); } double aver_ array2d ( int row, int col, double arr2d [ row ][ col ]) { int i, j; double total = 0.0; for ( i = 0; i < row ; i ++) for ( j = 0; j < col ; j ++) total += arr2d [i][j]; 194

vi } return total /( double ) ( row * col ); double max_ array2d ( int row, int col, double arr2d [ row ][ col ]) { int i, j; double max = arr2d [0][0]; for ( i = 0; i < row ; i ++) for ( j = 0; j < col ; j ++) if ( max < arr2d [i][j]) max = arr2d [i][j]; return max ; } 195

9 196

// ex09.h # include <stdio.h> # define ROWS 3 # define COLS 5 void input_ array2d ( int row, int col, double * arr2d ); void print_ array1d ( double * arr1d, int n); void print_ array2d ( int row, int col, double * arr2d ); void aver_ array2d_ row ( int row, int col, double * arr2d, double * average ); double aver_ array2d ( int row, int col, double * arr2d ); double max_ array2d ( int row, int col, double * arr2d ); 197

i // ex09.c # include " ex09.h" int main ( void ) { double arr2d [ ROWS * COLS ]; double average_ row [ ROWS ]; double average ; double max ; printf (" Please input 3 sets of five double numbers each.\n"); input_array2d (ROWS, COLS, arr2d ); printf (" The array is :\n"); print_array2d (ROWS, COLS, arr2d ); 198

ii aver_array2d_row (ROWS, COLS, arr2d, average_row ); printf (" average of each row :\n"); print_ array1d ( average_row, ROWS ); average = aver_ array2d ( ROWS, COLS, arr2d ); printf (" average of arr2d is %5.2 f\ n", average ); max = max_array2d (ROWS, COLS, arr2d ); printf (" max of arr2d is %5.2 f\n", max ); } return 0; void input_ array2d ( int row, int col, double * arr2d ) { int i; 199

iii } for (i = 0; i < row * col ; i ++) scanf ("%lf", & arr2d [i]); void print_ array1d ( double * arr1d, int n) { int i; for ( i = 0; i < n; i ++) printf (" %8.3 f", arr1d [i]); putchar ( \n ); } void print_ array2d ( int row, int col, double * arr2d ) { int r, c; for (r = 0; r < row ; r ++) { 200

iv } } for ( c = 0; c < col ; c ++) printf (" %8.2 f",arr2d [r* col +c]); putchar ( \n ); void aver_ array2d_ row ( int row, int col, double * arr2d, double * average ) { int r, c; double sum ; for (r = 0; r < row ; r ++) { sum = 0.0; for ( c = 0; c < col ; c ++) sum += arr2d [r* col +c]; 201

v } } average [ r] = sum / ( double ) col ; double aver_ array2d ( int row, int col, double * arr2d ) { int i; double total = 0.0; for (i = 1; i < row * col ; i ++) total += arr2d [ i]; return total /( double ) ( row * col ); } double max_ array2d ( int row, int col, double * arr2d ) { int i; 202

vi } double max = arr2d [0]; for (i = 1; i < row * col ; i ++) if ( max < arr2d [i]) max = arr2d [i]; return max ; 203