• 検索結果がありません。

練習&演習問題

N/A
N/A
Protected

Academic year: 2021

シェア "練習&演習問題"

Copied!
7
0
0

読み込み中.... (全文を見る)

全文

(1)

練習問題

(2)

#include <stdio.h>

#include <stdlib.h> /* srand(), rand() */ #include <time.h> /* time() */

int main(void) {

int i;

double a[5];

char filename[21] = "data.txt";

???? *fp; /* ファイルポインタの宣言 */ /* 乱数発生(0~1000までの乱数を100で割った値) */ srand((unsigned int)time(NULL)); for(i = 0; i < 5; i++){ a[i] = rand() % 1000 / 100.0; } /* ファイルを書き込みモードでオープンする */

if((fp = ?????(filename, ????)) == NULL){

printf("ファイルオープンに失敗しました.¥n"); return 0; }

練習問題1 ファイルへのデータ出力

配列 a[ ] の値をファイル data.txt に出力するプログラムを作成しなさい

1.23

2.45

3.56

4.78

5.91

data.txt

/* ファイルへデータを書き込む */ for(i = 0; i < 5; i++) ???????(fp, "%.2lf¥n", a[i]); fclose(fp); return 0; }

data.txtファイルが

できるので,

メモ帳などで確認

してみる

(3)

#include <stdio.h> #define N 5

int main(void) {

int i, n;

double a[N], sum;

char filename[21] = "data.txt"; FILE *fp;

/* ファイルを読み込みモードでオープンし */ /* ファイルポインタfpに接続 */

if((?? = fopen(filename, ????)) == NULL){

printf("ファイルオープンに失敗しました.¥n"); return 0;

}

/* ファイルの最後まで(EOFまで)読み込む */

i = 0;

while(??????(??, "%lf", &a[i]) != EOF){ i++; } n = i;

練習問題2 ファイルからのデータ入力

練習問題1で作成されたファイル data.txt からデータを読み込んで配列

a[ ] に格納したあと,配列 a[ ] の合計を計算するプログラムを作成しなさい

sum = 0.0; for(i = 0; i < n; i++){ printf("a[%d] = %.2lf¥n", i, a[i]); sum += a[i]; } printf("合計:%.2lf¥n", sum); ??????(fp); /* ファイルをクローズ */ return 0; }

1.23

2.45

3.56

4.78

5.91

data.txt

1.23

2.45

3.56

4.78

a[0]

a[1]

a[2]

a[3]

読み込む

(4)

#include <stdio.h> #define N 256 int main(void) { int i, counta; char buf[N];

char fnam[21] = "abstract.txt"; FILE *fp;

/* ファイルを読み込みモードでオープン */

if((fp = fopen(fnam, ????)) == NULL){

printf("[%s]:オープンに失敗¥n", fnam); return 0;

}

練習問題3 ファイルからの文字列入力

英文ファイル abstract.txt に含まれる 'a' および 'A' の文字数を数える

プログラムを作成しなさい

counta = 0;

/* ファイルから1行読み込むのをNULLまで繰り返す */

while(?????(buf, N, ??) != NULL){ i = 0; while(buf[i] != ????){ /* 文字列の最後まで */ /* 文字列の文字が'a'もしくは'A'であるかどうか */ if(buf[i] == ??? || buf[i] == ???){ ????????? /* そうであればcountaを+1*/ } ???? /* 次の文字を見る*/ } } fclose(fp); printf("‘a’ および ‘A’ は "); printf("%d 文字含まれる.¥n", counta); return 0; }

(5)

練習問題3 ファイルからの文字列入力(解説)

A new method is proposed for detection of the

temporal changes using 3-dimensional segmentation. The method is a kind of clustering methods for

temporal changes.[改行]

In the method, multi-temporal images form a image block in 3-dimensional space; x-y plane and time axis. [改行]

The image block is firstly divided into spatially uniform sub-blocks by applying binary division process. [改行]

The division rule is based on the statistical t-test using Mahalanobis distance between spatial

coefficient vectors of a local regression model fitted to neighboring sub-blocks to be divided. [改行]

The divided sub-blocks are, then, merged into clusters by using a clustering technique. [改行]

The block based processing such as the spatial segmentation technique is very effective in reduction of apparent changes due to noise. [改行]

Temporal change is detected as a boundary perpendicular to the time axis in the segmentation result. [改行]

The proposed method is successfully applied to actual multitemporal and multispectral LANDSAT/TM images. [EOF]

abstract.txt

ファイルから最大255文字

読み込み,buf [ ] に格納

char buf [ ] =

" A new method is ~ changes. "

A

n

e

w

e

s

.

¥0

m e

t

n

g

a

c

h

[0]

buf [ ]

[1] [2] [3] [4] [5] [6] [7] [8]

[90] [91] [92] [93] [94] [95] [96] [97] [98]

※ fgets によって[改行] まで読み込まれる

すなわち

実際には[改行]の

(6)

練習問題3 ファイルからの文字列入力(解説)

A

n

e

w

m e

t

~

c

h

a

n

g

e

s

.

¥0

[0]

buf [ ]

[1] [2] [3] [4] [5] [6] [7] [8]

[90] [91] [92] [93] [94] [95] [96] [97] [98]

文字列 buf [ ] に格納されている文字を1文字ずつ検索していく

'a' or 'A' ?

counta を +1 して次の文字を見る

A

n

e

w

m e

t

~

c

h

a

n

g

e

s

.

¥0

[0]

buf [ ]

[1] [2] [3] [4] [5] [6] [7] [8]

[90] [91] [92] [93] [94] [95] [96] [97] [98]

'a' or 'A' ?

何もしないで次の文字を見る

A

n

e

w

m e

t

~

c

h

a

n

g

e

s

.

¥0

[0]

buf [ ]

[1] [2] [3] [4] [5] [6] [7] [8]

[90] [91] [92] [93] [94] [95] [96] [97] [98]

'¥0' であれば,終了

(7)

練習問題3 ファイルからの文字列入力(解説)

A new method is proposed for detection of the

temporal changes using 3-dimensional segmentation. The method is a kind of clustering methods for

temporal changes.[改行]

In the method, multi-temporal images form a image block in 3-dimensional space; x-y plane and time axis. [改行]

The image block is firstly divided into spatially uniform sub-blocks by applying binary division process. [改行]

The division rule is based on the statistical t-test using Mahalanobis distance between spatial

coefficient vectors of a local regression model fitted to neighboring sub-blocks to be divided. [改行]

The divided sub-blocks are, then, merged into clusters by using a clustering technique. [改行]

The block based processing such as the spatial segmentation technique is very effective in reduction of apparent changes due to noise. [改行]

Temporal change is detected as a boundary perpendicular to the time axis in the segmentation result. [改行]

The proposed method is successfully applied to actual multitemporal and multispectral LANDSAT/TM

abstract.txt

EOF(ファイルの終わり)まで

参照

関連したドキュメント

The first case is the Whitham equation, where numerical evidence points to the conclusion that the main bifurcation branch features three distinct points of interest, namely a

Kilbas; Conditions of the existence of a classical solution of a Cauchy type problem for the diffusion equation with the Riemann-Liouville partial derivative, Differential Equations,

The linearized parabolic problem is treated using maximal regular- ity in analytic semigroup theory, higher order elliptic a priori estimates and simultaneous continuity in

Then it follows immediately from a suitable version of “Hensel’s Lemma” [cf., e.g., the argument of [4], Lemma 2.1] that S may be obtained, as the notation suggests, as the m A

Classical Sturm oscillation theory states that the number of oscillations of the fundamental solutions of a regular Sturm-Liouville equation at energy E and over a (possibly

While conducting an experiment regarding fetal move- ments as a result of Pulsed Wave Doppler (PWD) ultrasound, [8] we encountered the severe artifacts in the acquired image2.

p≤x a 2 p log p/p k−1 which is proved in Section 4 using Shimura’s split of the Rankin–Selberg L -function into the ordinary Riemann zeta-function and the sym- metric square

In the present paper, we show that, under the same hypothesis on the diameter of the tree, the group is an HNN extension with finitely presented base group, and hence that the