1 / 12

配列の扱い、探索 有効範囲と記憶域期間

第12回  [7月6日、H . 16(‘04)]. 配列の扱い、探索 有効範囲と記憶域期間. 今日のメニュー. 1 前回の課題の復習 2 前回の宿題の復習 3 今回の課題 6 演習. PE04-12 . ppt. 前回の課題. (1) List6-1 を参考に演習6ー1(118頁) (2) List6-2 を参考に演習6ー2(118頁) (3) List6-3 を参考に演習6ー3(119頁) List6-6 を参考に演習6ー4(121頁) (4) List6-7,8 を参考に演習6ー5(123頁) (5)演習6ー6(125頁).

Download Presentation

配列の扱い、探索 有効範囲と記憶域期間

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第12回 [7月6日、H.16(‘04)]第12回 [7月6日、H.16(‘04)] 配列の扱い、探索有効範囲と記憶域期間 今日のメニュー 1 前回の課題の復習 2 前回の宿題の復習 3 今回の課題 6 演習 PE04-12.ppt

  2. 前回の課題 (1)List6-1を参考に演習6ー1(118頁) (2)List6-2を参考に演習6ー2(118頁) (3)List6-3を参考に演習6ー3(119頁)List6-6を参考に演習6ー4(121頁) (4)List6-7,8を参考に演習6ー5(123頁) (5)演習6ー6(125頁) ファイル名はenB-****.c 提出はいつもと同様、リスト印刷とファイル転送

  3. 前回の宿題 (1)教科書の114頁~129頁を良く読んで復習する。 (2)教科書の120頁~145頁を良く読んで予習する。 (3)今日の課題が未完成の場合、完成して提出する。 ファイル名:hwB-****.c • 締め切り: 7月3日(土) 午後1時(厳守)

  4. #include <stdio.h> int minof( int x, int y) {} int min3( int x, int y, int z) {} int cube( int x) {} int pow4( int x) {} 演習6-1の関数の中身を記述 演習6-2の関数の中身を記述 関数sqrも作成し、利用すること 演習6-3の関数の中身を記述 演習6-4の関数の中身を記述

  5. voidalert( int no) { } voidhello( void ) {} 演習6-5の関数の中身を記述 演習6-6の関数の中身を記述 int main(void) { int na, nb, nc; /*演習6-1,6-2の場合*/ /*整数を入力する*/ printf("小さい方の値は %d です。\n",minof( na, nb) ); printf("3数中の最小値は %d です。\n",min3( na, nb, nc) );・・・・・・

  6. /*演習6-1、2、3*/ int minof(int x, int y) {return ( (x-y)>0 ? y : x );} int min3(int x, int y, int z) {int min = x; if ( y < min ) min = y; if ( z < min ) min = z;return (min);} int cube(int x) {return ( X*x*x);}・・・・ 関数内で利用する変数minの宣言と初期化

  7. 関数を利用する前に定義しておく /*演習6-4*/ int sqr(int x) { return ( x * x ); } int pow4(int x) { return ( sqr(x) * sqr(x) ); } sqr( sqr(x) ) /* main関数 */ int a;  ・・・・ printf("整数を入力せよ=>"); scanf("%d", &a); printf("四乗は %d です。\n",pow4(a));  ・・・・

  8. /*演習6-5、6*/ void alert(int no) {int i; for(i=0;i<no;i++)putchar('\a');} void hello( void ) { puts("こんにちは。");} while(no-->0)putchar('\a'); /* main関数 */  ・・・・ printf(" n=>");scanf("%d",&n);alert(n); hello(); ・・・・

  9. 課題の提出について ・main関数は最後に記述する ・演習6-4の pow4 は教科書List6-3の関数 sqr を用いる return(x*x*x*x); return(sqr(x)*sqr(x) ); return(sqr( sqr(x) ) ); ・プログラムの構成 #include <stdio.h>/* 関数1を定義する */int minof(・・・) {  ・・・} /* 関数2を定義する */   ・・・ int main(void) {int ・・・ puts("番号・氏名"); 必要な関数を呼び出す }

  10. 今回の課題 (1)List6-12、List6-13等参考にして、演習6-7、演習6-8、演習6-9(133頁)を完成せよ。 (2)List6-20 を参考に、演習6-12 を完成せよ。 (3)以下のプログラムを実行させ、関連する説明を復習せよ。(134-145頁) (a)List6-14(134頁)[逐次探索] (b)List6-15,16(136頁-)[番兵法] (c)List6-17(138頁)[多次元配列] (d)List6-18(140頁)[有効範囲] (e)List6-19(143頁)[記憶域期間] (1) → ファイル名:enC-****.cで提出 (2) → 授業の最後に答え合わせをする

  11. 今回の宿題 ファイル名:hwC-****.c 第10回の課題・宿題の続きとして、各科目・合計・平均点の最高点・最低点の出力を追加せよ。(最高点、最低点を求める関数を作る) 学籍番号 英語 数学 国語 合計点  平均点 1023 63 71 68 20267.33 1026 49 28 51 12842.67 : : : : 1132 81 89 75 24581.67 平均点   67.3 62.1 72.1 201.5 67.17 最高点 96 89 92 265 88.33 最低点 44 23 46 113 37.67 提出はいつもと同様、リスト印刷とファイル転送 • 締め切り: 7月10日(土) 午後1時(厳守)

  12. #include <stdio.h>/*演習6-12*/ int a[5]; int main(void){ static int b[5]; int i, c[5]; printf("\n a : "); for(i=0;i<5;i++) printf("%d",a[i]); printf("\n b : "); for(i=0;i<5;i++) printf("%d",b[i]); printf("\n c : "); for(i=0;i<5;i++) printf("%d",c[i]); printf("\n"); return (0); } 関数外で定義・宣言関数内でstatic付き 0に初期化される 自動記憶域期間の変数は不定値

More Related