C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2

Size: px
Start display at page:

Download "C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2"

Transcription

1 アセンブラ (Z80) の例 ORG 100H LD B,10 SUB A LOOP: ADD A,B DEC B JR NZ,LOOP LD (SUM),A HALT ORG 200H SUM: DEFS 1 END 1

2 C のコード例 (Z80 と同機能 ) int main(void) { int i,sum=0; for (i=1; i<=10; i++) sum=sum + i; printf ("sum=%d n",sum); 2

3 ベクトルの C による表現 C 言語でのデータ抽象化への模索 3

4 ベクトル ( 配列を使わない ) #include <stdio.h> main() { int a1=2,a2=4,a3=6; //vector a=( 2, 4, 6); int b1=12,b2=14,b3=16;//vector b=(12,14,16); int c1=0,c2=0,c3=0; //vector c=( 0, 0,0); /* vector c=a+b */ c1=a1+b1; c2=a2+b2; c3=a3+b3; printf("a=>(%d,%d,%d) n + n",a1,a2,a3); printf("b=>(%d,%d,%d) n = n",b1,b2,b3); printf("c=>(%d,%d,%d)",c1,c2,c3); 4

5 #include <stdio.h> main() { // 配列を使う int a[]={2,4,6; //vector a=( 2, 4, 6); int b[]={12,14,16;//vector b=(12,14,16); int c[]={0,0,0; //vetcot c=( 0, 0,0); /* vector c=a+b */ c[0]=a[0]+b[0]; c[1]=a[1]+b[1]; c[2]=a[2]+b[2]; printf(" 配列は使うが ループは使わない n"); printf("a=>(%d,%d,%d) n + n",a[0],a[1],a[2]); printf("b=>(%d,%d,%d) n = n",b[0],b[1],b[2]); printf("c=>(%d,%d,%d)",c[0],c[1],c[2]); ベクトル ( 配列を使う ) /* 実行結果配列は使うが ループは使わない a=>(2,4,6) + b=>(12,14,16) = 5 c=>(14,18,22) */

6 ベクトル ( 配列 + ループ ) #include <stdio.h> main() { // 配列を使う & ループを使う int a[]={2,4,6; //vector a=( 2, 4, 6); int b[]={12,14,16;//vector b=(12,14,16); int c[]={0,0,0; //vetcot c=( 0, 0,0); int array_max=sizeof(a)/sizeof(a[0]); // 配列の繰り返しの大きさを求める printf("array_max=%d n",array_max); /* vector c=a+b */ int i; // vector の a(i) への位置づけ用 for (i=0;i<array_max;i++) c[i]=a[i]+b[i]; printf(" 配列は使う & ループを使う n"); printf("a=>("); for (i=0;i<array_max-1;i++) printf("%d,",a[i]); printf("%d",a[array_max-1]); printf(") n + n"); printf("b=>("); for (i=0;i<array_max-1;i++) printf("%d,",b[i]); printf("%d",b[array_max-1]); printf(") n + n"); printf("c=>("); for (i=0;i<array_max-1;i++) printf("%d,",c[i]); printf("%d) n",c[array_max-1]); /* 実行結果 array_max=3 配列は使う & ループを使う a=>(2,4,6) + b=>(12,14,16) + c=>(14,18,22) */ 6

7 #include <stdio.h> void display(char *vecid,int *vector,int a_max) { 結果の表示を関数化 int i; printf("%s=>(",vecid); for (i=0;i<a_max-1;i++) printf("%d,",vector[i]); printf("%d",vector[a_max-1]); printf(") n"); main() { // 配列を使う & ループを使う & 結果の表示を関数化 int a[]={2,4,6; //vector a=( 2, 4, 6); int b[]={12,14,16;//vector b=(12,14,16); int c[]={0,0,0; //vetcot c=( 0, 0,0); int array_max=sizeof(a)/sizeof(a[0]); // 配列の繰り返しの大きさを求める printf("array_max=%d n",array_max); /* vector c=a+b */ int i; // vectorのa(i) への位置づけ用 for (i=0;i<array_max;i++) c[i]=a[i]+b[i]; printf(" 配列は使う & ループを使う & 結果の表 示を関数化 n"); display("a",a,array_max); printf(" + n"); display("b",b,array_max); printf(" = n"); display("c",c,array_max); 7

8 実行結果 /* 実行結果 array_max=3 配列は使う & ループを使う & 結果の表示を関数化 a=>(2,4,6) + b=>(12,14,16) = c=>(14,18,22)*/ 8

9 ベクトルの加算を関数化 (1) #include <stdio.h> #define MAX 3 typedef struct vec{ int v[max]; vector; void display(char *vecid,vector vec,int a_max) { int i; printf("%s=>(",vecid); for (i=0;i<a_max-1;i++) printf("%d,",vec.v[i]); printf("%d",vec.v[a_max-1]); printf(") n"); vector *vectoradd(vector aa,vector bb,int a_max) { int i; vector *ans; ans=(vector *)malloc(sizeof(vector)); for (i=0;i<a_max;i++) ans->v[i]=aa.v[i]+bb.v[i]; return ans; 9

10 ベクトルの加算を関数化 (2) main() { // 配列を使う & ループを使う & 結果の表示を関数化 & ベクトルの加算を関数化 // &typedef を使い vector 型を定義 vector a={2,4,6; //vector a=( 2, 4, 6); vector b={12,14,16;//vector b=(12,14,16); vector c={0,0,0; //vetcot c=( 0, 0,0); int array_max=sizeof(a.v)/sizeof(a.v[0]); // 配列の繰り返しの大きさを求める printf("array_max=%d n",array_max); /* vector c=a+b */ int i; // vector の a(i) への位置づけ用 c=*vectoradd(a,b,array_max); printf( 配列は使う & ループを使う & 結果の表 示を関数化 & ベクトルの加算を関数化 &typedef を使い vector 型を定義 n"); display("a",a,array_max); printf(" + n"); display("b",b,array_max); printf(" = n"); display("c",c,array_max); 10

11 ベクトルの加算を関数化 (3) /* 実行結果 array_max=3 配列は使う & ループを使う & 結果の表示を関数化 & ベクトルの加算を関数化 & typedef を使い vector 型を定義 a=>(2,4,6) + b=>(12,14,16) = c=>(14,18,22) */ 11

12 #include <stdio.h> #define MAX 3 typedef struct vec{ int v[max]; vector; void display(char *vecid,vector vec,int a_max) { int i; printf("%s=>(",vecid); for (i=0;i<a_max-1;i++) printf("%d,",vec.v[i]); printf("%d",vec.v[a_max-1]); printf(") n"); vector *vectoradd(vector aa,vector bb,vector ans,int i) { if ( i!= 0 ) { i--; ans.v[i]=aa.v[i]+bb.v[i]; ans=*vectoradd(aa,bb,ans,i); else ; return &ans; 再帰でループを実現 (1) 12

13 main() { // 再帰でループを実現 vector a={2,4,6; //vector a=( 2, 4, 6); vector b={12,14,16;//vector b=(12,14,16); vector c={0,0,0; //vetcot c=( 0, 0,0); 再帰でループを実現 (2) int array_max=sizeof(a.v)/sizeof(a.v[0]); // 配列の繰り返しの大きさ printf("array_max=%d n",array_max); /* vector c=a+b */ c=*vectoradd(a,b,c,array_max); printf(" 配列は使う & n"); printf(" &<< 再帰でループを実現 >> n"); display("a",a,array_max); printf(" + n"); display("b",b,array_max); printf(" = n"); display("c",c,array_max); /* 実行結果 array_max=3 配列は使う & &<< 再帰でループを実現 >> a=>(2,4,6) + b=>(12,14,16) = c=>(14,18,22) */ 13

14 #include <stdio.h> // Start of Abstract Data Type typedef struct vec{ int cell; struct vec *next; vector; 抽象データ型的 (1) void err2con(char* msg) { printf("error:%s:",msg); void display(char *vecid,vector **head) { vector *work=*head; int i; printf("%s=>(",vecid); while (work!= NULL){ if (work->next!= NULL) printf("%d,",work->cell); else printf("%d",work->cell); // ベクトルの最後の要素の後ろに, は付けない work=work->next; printf(") n"); 14

15 抽象データ型的 (2) vector *vectorconstructor(vector **head,int max,int value[]) { vector *work; int i; for (i=max-1;i>=0;i--) { if ((work = (vector *)malloc(sizeof(*work))) == NULL) { err2con("memory nothing"); return NULL; work->cell = value[i]; work->next = *head; *head = work; printf("cell=%d ",work->cell); return *head; 15

16 抽象データ型的 (3) void vectoradd(vector **aa,vector **bb,vector **ans) { vector *a=*aa; vector *b=*bb; vector *c=*ans; while (c!= NULL){ c->cell = a->cell + b->cell; a=a->next; b=b->next; c=c->next; vectordestructor(vector **head){ vector *work=*head; while (work!= NULL){ free(work); work=work->next; // End of Abstract Data Type 16

17 main() { // 抽象データ型的抽象データ型的 (4) vector *ahead=null; vector *bhead=null; vector *chead=null; int a[]={2,4,6; int b[]={12,14,16; int c[]={0,0,0; // コンストラクタの呼び出しを擬似る vectorconstructor(&ahead,3,a); //vector a=( 2, 4, 6); vectorconstructor(&bhead,3,b); //vector b=(12,14,16); vectorconstructor(&chead,3,c); //vetcot c=( 0, 0,0); /* メソッド ( ベクトル加算 ) の呼び出しvector c=a+b */ vectoradd(&ahead,&bhead,&chead); printf(" n 抽象データ型的な方式 n"); // メソッド ( ベクトルの表示 ) の呼び出し display("a",&ahead); printf(" + n"); display("b",&bhead); printf(" = n"); display("c",&chead); // デストラクタの呼び出しを擬似る vectordestructor(&ahead); vectordestructor(&bhead); 17 vectordestructor(&chead);

18 抽象データ型的 (5) /* 実行結果 cell=6 cell=4 cell=2 cell=16 cell=14 cell=12 cell=0 cell=0 cell=0 抽象データ型的な方式 a=>(2,4,6) + b=>(12,14,16) = c=>(14,18,22) */ 18

19 C++ による演算子定義 (1) #include <iostream> using namespace std; #define MAX 5 class vec { int cell[max]; public: vec(); vec(int a,int b,int c,int d,int e); void get(int v[max]); vec operator+(vec v); vec operator*(int c); vec operator=(vec v); ; vec::vec() { for(int i=0;i<max;i++) cell[i]=0; vec::vec(int a,int b,int c,int d,int e) { cell[0]=a; cell[1]=b; cell[2]=c; cell[3]=d; cell[4]=e; void vec::get(int v[max]) { for(int i=0;i<max;i++) v[i]=cell[i]; 19

20 vec vec::operator+(vec v) { vec wk; for(int i=0;i<max;i++) wk.cell[i]=cell[i] + v.cell[i]; return wk; C++ による演算子定義 (2) vec vec::operator*(int c) { vec wk; for(int i=0;i<max;i++) wk.cell[i]=cell[i] * c; return wk; vec vec::operator=(vec v) { for(int i=0;i<max;i++) cell[i]=v.cell[i]; return *this; 20

21 int main() { int cell[max]; vec a(10,20,30,40,50),b(1,2,3,4,5),c(0,0,0,0,0); c = a + b; c.get(cell); C++ による演算子定義 (3) cout << "a+b => "; for(int i=0;i<max;i++) cout << cell[i] << " "; cout <<" n"; c = a * 10; c.get(cell); cout << "a*10 => "; for(int i=0;i<max;i++) cout << cell[i] << " "; cout <<" n"; c = a * 10 + b; c.get(cell); cout << "a*10+b => "; for(int i=0;i<max;i++) cout << cell[i] << " "; cout <<" n"; c = (a + b) * 10; c.get(cell); cout << "(a+b)*10 => "; for(int i=0;i<max;i++) cout << cell[i] << " "; cout <<" n"; a.get(cell); cout << " 今の a を表 示 "; for(int i=0;i<max;i++) cout << cell[i] << " "; cout <<" n a = c; a.get(cell); cout << "c を a に代入したあとの c を表 示 "; for(int i=0;i<max;i++) cout << cell[i] << " "; cout <<" n"; return 0; 21

22 C++ による演算子定義 (4) /* // 実行例 a+b => a*10 => a*10+b => (a+b)*10 => 今の a を表示 c を a に代入したあとの c を表示 */ 22

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード]

Microsoft PowerPoint - C言語の復習(配布用).ppt [互換モード] if 文 (a と b の大きい方を表示 ) C 言語 Ⅰ の復習 条件判定 (if, 条件式 ) ループ (for[ 二重まで ], while, do) 配列 ( 次元 次元 ) トレース int a, b; printf( 整数 a: ); scanf( %d, &a); printf( 整数 b: ); scanf( %d, &b); //つのif 文で表現する場合間違えやすい どっちに =

More information

新・明解C言語で学ぶアルゴリズムとデータ構造

新・明解C言語で学ぶアルゴリズムとデータ構造 第 1 章 基本的 1 n 141 1-1 三値 最大値 algorithm List 1-1 a, b, c max /* */ #include int main(void) { int a, b, c; int max; /* */ List 1-1 printf("\n"); printf("a"); scanf("%d", &a); printf("b"); scanf("%d",

More information

C言語によるアルゴリズムとデータ構造

C言語によるアルゴリズムとデータ構造 Algorithms and Data Structures in C 4 algorithm List - /* */ #include List - int main(void) { int a, b, c; int max; /* */ Ÿ 3Ÿ 2Ÿ 3 printf(""); printf(""); printf(""); scanf("%d", &a); scanf("%d",

More information

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout <<

3.1 stdio.h iostream List.2 using namespace std C printf ( ) %d %f %s %d C++ cout cout List.2 Hello World! cout << float a = 1.2f; int b = 3; cout << C++ C C++ 1 C++ C++ C C++ C C++? C C++ C *.c *.cpp C cpp VC C++ 2 C++ C++ C++ [1], C++,,1999 [2],,,2001 [3], ( )( ),,2001 [4] B.W. /D.M.,, C,,1989 C Web [5], http://kumei.ne.jp/c_lang/ 3 Hello World Hello

More information

Taro-再帰関数Ⅲ(公開版).jtd

Taro-再帰関数Ⅲ(公開版).jtd 0. 目次 1 1. ソート 1 1. 1 挿入ソート 1 1. 2 クイックソート 1 1. 3 マージソート - 1 - 1 1. ソート 1 1. 1 挿入ソート 挿入ソートを再帰関数 isort を用いて書く 整列しているデータ (a[1] から a[n-1] まで ) に a[n] を挿入する操作を繰り返す 再帰的定義 isort(a[1],,a[n]) = insert(isort(a[1],,a[n-1]),a[n])

More information

PowerPoint プレゼンテーション

PowerPoint プレゼンテーション プログラミング応用演習 第 4 回再帰的構造体 プログラミングを 余談 : 教えることの難しさ 丁寧に説明しないと分かってもらえない 説明すると 小難しくなる学生が目指すべきところプログラム例を説明されて理解できる違うやり方でも良いので自力で解決できる おっけー 動けば良い という意識でプログラミング 正しく動くことのチェックは必要 解答例と自分のやり方との比較が勉強になる 今日のお題 再帰的構造体

More information

memo

memo 数理情報工学演習第一 C プログラミング演習 ( 第 5 回 ) 2015/05/11 DEPARTMENT OF MATHEMATICAL INFORMATICS 1 今日の内容 : プロトタイプ宣言 ヘッダーファイル, プログラムの分割 課題 : 疎行列 2 プロトタイプ宣言 3 C 言語では, 関数や変数は使用する前 ( ソースの上のほう ) に定義されている必要がある. double sub(int

More information

Microsoft PowerPoint - 説明3_if文switch文(C_guide3)【2015新教材対応確認済み】.pptx

Microsoft PowerPoint - 説明3_if文switch文(C_guide3)【2015新教材対応確認済み】.pptx 情報ネットワーク導入ユニット Ⅰ C 言語 if 文 switch 文 3 章 : プログラムの流れの分岐 if 文 if( 条件 ) 条件が成立すれば実行 if( 条件 ) ~ else 場合分け ( 成立, 不成立 ) if( 条件 A) ~ else if( 条件 B) ~ else if( 条件 C) ~ else 場合分け ( 複数の条件での場合分け ) 等価演算子 : == ( 等しい

More information

新・明解C言語 実践編

新・明解C言語 実践編 第 1 章 見 21 1-1 見えないエラー 見 List 1-1 "max2x1.h" a, b max2 List 1-1 chap01/max2x1.h max2 "max2x1.h" #define max2(a, b) ((a) > (b)? (a) : (b)) max2 List 1-2 List 1-2 chap01/max2x1test.c max2 #include

More information

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10; (STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector x; for(int i = 0; i < 10; ++i) x.push_back(i); vector STL x.push_back(i) STL

More information

新版明解C言語 実践編

新版明解C言語 実践編 2 List - "max.h" a, b max List - max "max.h" #define max(a, b) ((a) > (b)? (a) : (b)) max List -2 List -2 max #include "max.h" int x, y; printf("x"); printf("y"); scanf("%d", &x); scanf("%d", &y); printf("max(x,

More information

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科

バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科 バイオプログラミング第 1 榊原康文 佐藤健吾 慶應義塾大学理工学部生命情報学科 ポインタ変数の扱い方 1 ポインタ変数の宣言 int *p; double *q; 2 ポインタ変数へのアドレスの代入 int *p; と宣言した時,p がポインタ変数 int x; と普通に宣言した変数に対して, p = &x; は x のアドレスのポインタ変数 p への代入 ポインタ変数の扱い方 3 間接参照 (

More information

cpp1.dvi

cpp1.dvi 2017 c 1 C++ (1) C C++, C++, C 11, 12 13 (1) 14 (2) 11 1 n C++ //, [List 11] 1: #include // C 2: 3: int main(void) { 4: std::cout

More information

DVIOUT

DVIOUT 2005 年度プログラミング演習 II レポート 7 学生用 学籍番号 : 氏名 : 下記の注意事項を守り 次ページ以降の問いに答え レポートを完成させなさい 提出期限 : 2005 年 12 月 13 日 ( 火 ) 13:15 まで提出場所 : 理学部棟正面玄関内に設置のレポートボックス 注意事項 : (1) このページを印刷し 必要事項を記入の上 ( 学籍番号欄と氏名欄は 2 箇所あるので忘れずに記入すること

More information

1.ppt

1.ppt /* * Program name: hello.c */ #include int main() { printf( hello, world\n ); return 0; /* * Program name: Hello.java */ import java.io.*; class Hello { public static void main(string[] arg)

More information

C プログラミング演習 1( 再 ) 2 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ

C プログラミング演習 1( 再 ) 2 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ C プログラミング演習 1( 再 ) 2 講義では C プログラミングの基本を学び 演習では やや実践的なプログラミングを通して学ぶ 今回のプログラミングの課題 次のステップによって 徐々に難易度の高いプログラムを作成する ( 参照用の番号は よくわかる C 言語 のページ番号 ) 1. キーボード入力された整数 10 個の中から最大のものを答える 2. 整数を要素とする配列 (p.57-59) に初期値を与えておき

More information

C#の基本2 ~プログラムの制御構造~

C#の基本2 ~プログラムの制御構造~ C# の基本 2 ~ プログラムの制御構造 ~ 今回学ぶ事 プログラムの制御構造としての単岐選択処理 (If 文 ) 前判定繰り返し処理(for 文 ) について説明を行う また 整数型 (int 型 ) 等の組み込み型や配列型についても解説を行う 今回作るプログラム 入れた文字の平均 分散 標準偏差を表示するプログラム このプログラムでは calc ボタンを押すと計算を行う (value は整数に限る

More information

プログラミング基礎

プログラミング基礎 C プログラミング Ⅱ 演習 2-1(a) BMI による判定 文字列, 身長 height(double 型 ), 体重 weight (double 型 ) をメンバとする構造体 Data を定義し, それぞれのメンバの値をキーボードから入力した後, BMI を計算するプログラムを作成しなさい BMI の計算は関数化すること ( ) [ ] [ ] [ ] BMI = 体重 kg 身長 m 身長

More information

kiso2-06.key

kiso2-06.key 座席指定があります Linux を起動して下さい 第6回 計算機基礎実習II 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 第5回の復習課題(rev05) 第6回の基本課題(base06) 第5回課題の回答例 ex05-2.c 1. キーボードから整数値 a を入力すると a*a*a の値を出力することを繰り返すプログラムを作成しなさい 2. ただし 入力された

More information

r07.dvi

r07.dvi 19 7 ( ) 2019.4.20 1 1.1 (data structure ( (dynamic data structure 1 malloc C free C (garbage collection GC C GC(conservative GC 2 1.2 data next p 3 5 7 9 p 3 5 7 9 p 3 5 7 9 1 1: (single linked list 1

More information

ohp07.dvi

ohp07.dvi 19 7 ( ) 2019.4.20 1 (data structure) ( ) (dynamic data structure) 1 malloc C free 1 (static data structure) 2 (2) C (garbage collection GC) C GC(conservative GC) 2 2 conservative GC 3 data next p 3 5

More information

untitled

untitled II yacc 005 : 1, 1 1 1 %{ int lineno=0; 3 int wordno=0; 4 int charno=0; 5 6 %} 7 8 %% 9 [ \t]+ { charno+=strlen(yytext); } 10 "\n" { lineno++; charno++; } 11 [^ \t\n]+ { wordno++; charno+=strlen(yytext);}

More information

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2 " 2 B R b

I ASCII ( ) NUL 16 DLE SP P p 1 SOH 17 DC1! 1 A Q a q STX 2 18 DC2  2 B R b I 4 003 4 30 1 ASCII ( ) 0 17 0 NUL 16 DLE SP 0 @ P 3 48 64 80 96 11 p 1 SOH 17 DC1! 1 A Q a 33 49 65 81 97 113 q STX 18 DC " B R b 34 50 66 8 98 114 r 3 ETX 19 DC3 # 3 C S c 35 51 67 83 99 115 s 4 EOT

More information

Taro-2分探索木Ⅰ(公開版).jtd

Taro-2分探索木Ⅰ(公開版).jtd 2 分探索木 Ⅰ 0. 目次 1. 2 分探索木とは 2. 2 分探索木の作成 3. 2 分探索木の走査 3. 1 前走査 3. 2 中走査 3. 3 問題 問題 1 問題 2 後走査 4. 2 分探索木の表示 - 1 - 1. 2 分探索木とは 木はいくつかの節点と節点同士を結ぶ辺から構成される 2 つの節点 u,v が直接辺で結ばれているとき 一方を親節点 他方を子節点という ある節点の親節点は高々

More information

untitled

untitled II 4 Yacc Lex 2005 : 0 1 Yacc 20 Lex 1 20 traverse 1 %% 2 [0-9]+ { yylval.val = atoi((char*)yytext); return NUM; 3 "+" { return + ; 4 "*" { return * ; 5 "-" { return - ; 6 "/" { return / ; 7 [ \t] { /*

More information

Taro-プログラミングの基礎Ⅱ(公

Taro-プログラミングの基礎Ⅱ(公 0. 目次 2. プログラムの作成 2. 1 コラッツ問題 自然数 n から出発して n が偶数ならば 2 で割り n が奇数ならば 3 倍して 1 を足す操作を行う この操作を繰り返すと最後に 1 になると予想されている 問題 1 自然数 aの操作回数を求めよ 問題 2 自然数 aから bまでのなかで 最大操作回数となる自然数を求めよ 2. 2 耐久数 正整数の各桁の数字を掛け 得られた結果についても同様の操作を繰り返す

More information

Taro-ポインタ変数Ⅰ(公開版).j

Taro-ポインタ変数Ⅰ(公開版).j 0. 目次 1. ポインタ変数と変数 2. ポインタ変数と配列 3. ポインタ変数と構造体 4. ポインタ変数と線形リスト 5. 問題 問題 1 問題 2-1 - 1. ポインタ変数と変数 ポインタ変数には 記憶領域の番地が格納されている 通常の変数にはデータが格納されている 宣言 int *a; float *b; char *c; 意味ポインタ変数 aは 整数型データが保存されている番地を格納している

More information

情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤

情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤 情報工学実験 C コンパイラ第 2 回説明資料 (2017 年度 ) 担当 : 笹倉 佐藤 2017.12.7 前回の演習問題の解答例 1. 四則演算のできる計算機のプログラム ( 括弧も使える ) 2. 実数の扱える四則演算の計算機のプログラム ( 実数 も というより実数 が が正しかったです ) 3. 変数も扱える四則演算の計算機のプログラム ( 変数と実数が扱える ) 演習問題 1 で行うべきこと

More information

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v

/* do-while */ #include <stdio.h> #include <math.h> int main(void) double val1, val2, arith_mean, geo_mean; printf( \n ); do printf( ); scanf( %lf, &v 1 http://www7.bpe.es.osaka-u.ac.jp/~kota/classes/jse.html [email protected] /* do-while */ #include #include int main(void) double val1, val2, arith_mean, geo_mean; printf( \n );

More information

Taro-スタック(公開版).jtd

Taro-スタック(公開版).jtd 0. 目次 1. 1. 1 配列によるの実現 1. 2 再帰的なデータ構造によるの実現 1. 3 地図情報処理 1. 4 問題 問題 1 グラフ探索問題 - 1 - 1. は データの出し入れが一カ所で行われ 操作は追加と削除ができるデータ構造をいう 出入口 追加 削除 操作 最初 111 追加 111 222 追加 111 222 333 追加 111 222 333 444 追加 111 222

More information

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU

PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 1. 1.1. 1.2. 1 PC Windows 95, Windows 98, Windows NT, Windows 2000, MS-DOS, UNIX CPU 2. 2.1. 2 1 2 C a b N: PC BC c 3C ac b 3 4 a F7 b Y c 6 5 a ctrl+f5) 4 2.2. main 2.3. main 2.4. 3 4 5 6 7 printf printf

More information

cp-7. 配列

cp-7. 配列 cp-7. 配列 (C プログラムの書き方を, パソコン演習で学ぶシリーズ ) https://www.kkaneko.jp/cc/adp/index.html 金子邦彦 1 本日の内容 例題 1. 月の日数配列とは. 配列の宣言. 配列の添え字. 例題 2. ベクトルの内積例題 3. 合計点と平均点例題 4. 棒グラフを描く配列と繰り返し計算の関係例題 5. 行列の和 2 次元配列 2 今日の到達目標

More information

PowerPoint Presentation

PowerPoint Presentation p.130 p.198 p.208 2 double weight[num]; double min, max; min = max = weight[0]; for( i= 1; i i < NUM; i++ ) ) if if ( weight[i] > max ) max = weight[i]: if if ( weight[i] < min ) min = weight[i]: weight

More information

ohp03.dvi

ohp03.dvi 19 3 ( ) 2019.4.20 CS 1 (comand line arguments) Unix./a.out aa bbb ccc ( ) C main void int main(int argc, char *argv[]) {... 2 (2) argc argv argc ( ) argv (C char ) ( 1) argc 4 argv NULL. / a. o u t \0

More information

RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用

RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用 RX ファミリ用 C/C++ コンパイラ V.1.00 Release 02 ご使用上のお願い RX ファミリ用 C/C++ コンパイラの使用上の注意事項 4 件を連絡します #pragma option 使用時の 1 または 2 バイトの整数型の関数戻り値に関する注意事項 (RXC#012) 共用体型のローカル変数を文字列操作関数で操作する場合の注意事項 (RXC#013) 配列型構造体または共用体の配列型メンバから読み出した値を動的初期化に用いる場合の注意事項

More information

プログラミングI第10回

プログラミングI第10回 プログラミング 1 第 10 回 構造体 (3) 応用 リスト操作 この資料にあるサンプルプログラムは /home/course/prog1/public_html/2007/hw/lec/sources/ 下に置いてありますから 各自自分のディレクトリにコピーして コンパイル 実行してみてください Prog1 2007 Lec 101 Programming1 Group 19992007 データ構造

More information

gengo1-11

gengo1-11 関数の再帰定義 自然数 n の階乗 n! を計算する関数を定義してみる 引数は整数 返却値も整数 n! = 1*2*3*... * (n 1)*n である ただし 0! = 1 とする int factorial(int n) int i, tmp=1; if( n>0 ) for(i=1; i

More information

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >=

void hash1_init(int *array) int i; for (i = 0; i < HASHSIZE; i++) array[i] = EMPTY; /* i EMPTY */ void hash1_insert(int *array, int n) if (n < 0 n >= II 14 2018 7 26 : : [email protected] 14,, 8 2 12:00 1 O(1) n O(n) O(log n) O(1) 32 : 1G int 4 250 M 2.5 int 21 2 0 100 0 100 #include #define HASHSIZE 100 /* */ #define NOTFOUND 0

More information

Taro-ファイル処理(公開版).jtd

Taro-ファイル処理(公開版).jtd ファイル処理 0. 目次 1. はじめに 2. ファイル内容の表示 3. ファイル内容の複写 3. 1 文字単位 3. 2 行単位 4. 書式付き入出力 5. 文字配列への入出力 6. 課題 6. 1 課題 1 ( ファイル圧縮 復元 ) - 1 - 1. はじめに ファイル処理プログラムの形は次のようになる #include main() { FILE *fp1,*fp2; ファイルポインタの宣言

More information

Microsoft Word - C言語研修 C++編 3.doc

Microsoft Word - C言語研修 C++編 3.doc 2006/05/10 オブジェクト指向... 3 1 クラスの継承... 3 2 継承の書式... 3 3 protected... 5 4 メンバ関数のオーバーライド... 6 5 クラスの型キャスト... 7 6 仮想関数... 8 2 オブジェクト指向 1 クラスの継承 クラスには 継承 という機能があります 継承とは 既にあるクラスを元に 新しいクラスを作る 機能です 継承元のクラスを 親クラス

More information

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l

1 C STL(1) C C C libc C C C++ STL(Standard Template Library ) libc libc C++ C STL libc STL iostream Algorithm libc STL string vector l C/C++ 2007 6 18 1 C STL(1) 2 1.1............................................... 2 1.2 stdio................................................ 3 1.3.......................................... 10 2 11 2.1 sizeof......................................

More information

/*Source.cpp*/ #include<stdio.h> //printf はここでインクルードして初めて使えるようになる // ここで関数 average を定義 3 つの整数の平均値を返す double 型の関数です double average(int a,int b,int c){

/*Source.cpp*/ #include<stdio.h> //printf はここでインクルードして初めて使えるようになる // ここで関数 average を定義 3 つの整数の平均値を返す double 型の関数です double average(int a,int b,int c){ ソフトゼミ A 第 6 回 関数 プログラムは関数の組み合わせでできています 今までのゼミAでも printf や scanf など様々な関数を使ってきましたが なんと関数は自分で作ることもできるのです!! 今日は自作関数を中心に扱っていきます ゲーム制作でも自作関数は避けては通れないので頑張りましょう そもそもまず 関数とは 基本的には 受け取った値に関数によって定められた操作をして その結果の値を返す

More information

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç

C¥×¥í¥°¥é¥ß¥ó¥° ÆþÌç C (3) if else switch AND && OR (NOT)! 1 BMI BMI BMI = 10 4 [kg]) ( [cm]) 2 bmi1.c Input your height[cm]: 173.2 Enter Input your weight[kg]: 60.3 Enter Your BMI is 20.1. 10 4 = 10000.0 1 BMI BMI BMI = 10

More information

Microsoft Word - Cプログラミング演習(12)

Microsoft Word - Cプログラミング演習(12) 第 12 回 (7/9) 4. いくつかのトピック (5)main 関数の引数を利用したファイル処理 main 関数は, 起動する環境から引数を受け取ることができる 例えば 次に示すように,main 関数に引数を用いたプログラムを作成する 01 /* sample */ 02 /* main 関数の引数 */ 03 #include 04 05 main(int argc, char

More information

design_pattern.key

design_pattern.key #include void init(int* ary, int size) for (int i = 0; i < size; ++i) ary[i] = i; void mul10(int* ary, int size) for (int i = 0; i < size; ++i) ary[i] *= 10; void dispary(int* ary, int size)

More information

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * *

I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) + x * x + x x (4) * * 2015 2015 07 30 10:30 12:00 I. I VI II. III. IV. a d V. VI. 80 100 60 1 I. Backus-Naur BNF S + S S * S S x S +, *, x BNF S (parse tree) : * x + x x S * S x + S S S x x (1) * x x * x (2) * + x x x (3) +

More information

kiso2-03.key

kiso2-03.key 座席指定はありません Linux を起動して下さい 第3回 計算機基礎実習II 2018 のウェブページか ら 以下の課題に自力で取り組んで下さい 計算機基礎実習II 第2回の復習課題(rev02) 第3回の基本課題(base03) 第2回課題の回答例 ex02-2.c include int main { int l int v, s; /* 一辺の長さ */ /* 体積 v

More information

Undestand の解析 Understand の C 言語で抽出できない依存関係について サンプルコードを用いて説明します 確認バージョン Understand 3.0 (Build 640) Understand 3.1 (Build 700) Understand 4.0 (Build 78

Undestand の解析 Understand の C 言語で抽出できない依存関係について サンプルコードを用いて説明します 確認バージョン Understand 3.0 (Build 640) Understand 3.1 (Build 700) Understand 4.0 (Build 78 Undestand の解析 Understand の C 言語で抽出できない依存関係について サンプルコードを用いて説明します 確認バージョン Understand 3.0 (Build 640) Understand 3.1 (Build 700) Understand 4.0 (Build 788) 抽出できない依存関係 Understand の C 言語の解析 (Fuzzy/Strict) で

More information