PowerPoint プレゼンテーション

Similar documents
ゲームエンジンの構成要素

文字列 2 前回の授業ではコンピュータ内部での文字の取り扱い 文字型の変数 文字型変数への代入方法などを学習した 今回は 前回に引き続き 文字処理を学習する 内容は 標準入出力 ( キーボード ディスプレイ ) での文字処理 文字のファイル処理 文字を取り扱うライブラリ関数である 標準入出力 Lin

PowerPoint Presentation

数値計算

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

Microsoft PowerPoint - CproNt11.ppt [互換モード]

ポインタ変数

ポインタ変数

Microsoft Word - 18環設演付録0508.doc

ファイル入出力

講習No.12

卒 業 研 究 報 告.PDF

1. 入力した文字列を得る 1.1. 関数 scanf() を使う まずは関数 scanf() を使ったプログラムを作ってみましょう 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: #include<stdio.h> #define SIZE 128 main(

ファイル入出力

prog-text.dvi

‚æ2›ñ C„¾„ê‡Ìš|

C 言語第 3 回 2 a と b? 関係演算子 a と b の関係 関係演算子 等しい a==b 等しくない a!=b より大きい a>b 以上 a>=b より小さい a<b 以下 a<=b 状態 真偽 値 条件が満たされた場合 TRUE( 真 ) 1(0 以外 ) 条件が満たされなかった場合 F

Microsoft PowerPoint - kougi4.ppt

joho07-1.ppt

mstrcpy char *mstrcpy(const char *src); mstrcpy malloc (main free ) stdio.h fgets char *fgets(char *s, int size, FILE *stream); s size ( )

Microsoft PowerPoint - 3.ppt [互換モード]

Microsoft PowerPoint - kougi6.ppt

Microsoft PowerPoint - prog05.ppt

PowerPoint Presentation

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

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) * *

スライド 1

V

数値計算

02: 変数と標準入出力

プログラミング基礎

kiso2-06.key

Microsoft Word - no11.docx

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

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

Microsoft PowerPoint - 5Chap15.ppt

USB ID TA DUET 24:00 DUET XXX -YY.c ( ) XXX -YY.txt() XXX ID 3 YY ID 5 () #define StudentID 231

超初心者用

I. Backus-Naur BNF : N N 0 N N N N N N 0, 1 BNF N N 0 11 (parse tree) 11 (1) (2) (3) (4) II. 0(0 101)* (

情報処理演習 B8クラス

ポインタ変数

Microsoft PowerPoint - kougi9.ppt

プログラミング基礎

memo

ポインタ変数

A/B (2018/10/19) Ver kurino/2018/soft/soft.html A/B

:30 12:00 I. I VI II. III. IV. a d V. VI

02: 変数と標準入出力

C言語講座 ~ファイル入出力編~

計算機プログラミング

演算増幅器

Microsoft PowerPoint - 4.ppt [互換モード]

02: 変数と標準入出力

8 / 0 1 i++ i 1 i-- i C !!! C 2

講習No.9

PowerPoint Presentation

C 言語講座 Vol 年 5 月 29 日 CISC

Prog1_10th

#include<math.h> 数学関係の関数群で sin() cos() tan() などの三角関数や累乗の pow() 平方根を求める sqrt() 対数 log() などがあります #include<string.h> 文字列を扱う関数群 コイツもまた後日に 4. 自作関数 実は 関数は自分

slide4.pptx

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

Microsoft Word - 3new.doc

* ライブラリ関数 islower(),toupper() を使ったプログラム 1 /* 2 Program : trupper.c 3 Student-ID : K 4 Author : TOUME, Kouta 5 Comments : Used Library function i

Microsoft PowerPoint - guidance.ppt

PowerPoint Presentation

Microsoft PowerPoint pptx

Microsoft PowerPoint - 3.pptx

:30 12:00 I. I VI II. III. IV. a d V. VI

講習No.10

Microsoft PowerPoint - prog04.ppt

/* 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

プログラミング実習I

1 return main() { main main C 1 戻り値の型 関数名 引数 関数ブロックをあらわす中括弧 main() 関数の定義 int main(void){ printf("hello World!!\n"); return 0; 戻り値 1: main() 2.2 C main

no35.dvi

+ +

ポインタ変数

9 ライブラリ関数 ( 教科書 P.84) C 言語には使用頻度が高そうな機能は関数として用意されており, それらは幾つかのライブラリに分類されている. それらの総称を C 言語標準ライブラリと呼ぶ. 次を参照のこと.

本サンプル問題の著作権は日本商工会議所に帰属します また 本サンプル問題の無断転載 無断営利利用を厳禁します 本サンプル問題の内容や解答等に関するお問 い合わせは 受け付けておりませんので ご了承ください 日商プログラミング検定 STANDARD(C 言語 ) サンプル問題 知識科目 第 1 問 (

FORTRAN( と C) によるプログラミング 5 ファイル入出力 ここではファイルからデータを読みこんだり ファイルにデータを書き出したりするプログラムを作成してみます はじめに テキスト形式で書かれたデータファイルに書かれているデータを読みこんで配列に代入し 標準出力に書き出すプログラムを作り

Microsoft Word - no202.docx

Microsoft PowerPoint - kougi2.ppt

Prog1_6th

PowerPoint プレゼンテーション

Prog1_15th

Microsoft PowerPoint - CproNt02.ppt [互換モード]

プログラミング実習I

70 : 20 : A B (20 ) (30 ) 50 1

スライド タイトルなし

高等学校学習指導要領

高等学校学習指導要領

プログラミング基礎

問 2 ( 型変換 ) 次のプログラムを実行しても正しい結果が得られない 何が間違いかを指摘し 正しく修正せよ ただし int サイズが 2 バイト long サイズが 4 バイトの処理系での演算を仮定する #include <stdio.h> int main( void ) { int a =

ディジタル信号処理

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

02: 変数と標準入出力

Microsoft Word - cpro_m_13.doc

Microsoft PowerPoint - 14th.ppt [互換モード]

Microsoft PowerPoint - 10Com2.ppt

1.ppt

untitled

Transcription:

プログラミング初級 第 13 回 2017 年 7 月 10 日 標準ライブラリ関数 1

標準ライブラリ関数とは 関数には (1) 自分で作る関数 (2) はじめから用意されている関数特に C 言語用用意されているもの : 標準ライブラリ関数 文字列の代入文字列の長さを求める文字列の比較文字列の連結 strcpy strlen strcmp strcat 2

文字列の操作 - 具体例を通して (141 ページ ) #include <stdio.h> #include <string.h> int main(void) { char s1[80],s2[80]; int nn; strcpy(s1, abcde ); strcpy(s2, FGHIJ ); printf( s1=%s s2=%s n,s1,s2); nn=strlen(s1); printf( len=%d n, nn); if(strcmp(s1, s2) > 0) printf( 左辺が大 n ); if(strcmp(s1, s2) < 0) printf( 右辺が大 n ); } if(strcmp(s1, s2) == 0) printf( 等しい n ); if(strcmp(s1, s2)!= 0) printf( 等しくない n ); strcat(s1, s2); printf( s1+s2=%s n,s1); return 0; 3

文字列の操作 - 具体例を通して (141 ページ ) #include <stdio.h> #include <string.h> int main(void) { char s1[80],s2[80]; int nn; strcpy(s1, abcde ); strcpy(s2, FGHIJ ); printf( s1=%s s2=%s n,s1,s2); 文字列処理をするときはつける ( と覚える ) < 文字列の代入 > if(strcmp(s1, s2) == 0) printf( 等しい n ); if(strcmp(s1, s2)!= 0) printf( 等しくない n ); strcpy( 代入される文字列変数 代入する文字列 ) nn=strlen(s1); printf( len=%d n, nn); strcat(s1, s2); printf( s1+s2=%s n,s1); if(strcmp(s1, s1 s2) [0] > 0) [1] [2] [3] [4] return [5] 0; [6] [7] [8] [9] printf( 左辺が大 n ); } if(strcmp(s1, s2) a< 0) b c d e 0 printf( 右辺が大 n ); s2 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] F G H I J 0 4

文字列の操作 - 具体例を通して (141 ページ ) #include <stdio.h> #include <string.h> int main(void) { char s1[80],s2[80]; int nn; strcpy(s1, abcde ); strcpy(s2, FGHIJ ); printf( s1=%s s2=%s n,s1,s2); nn=strlen(s1); printf( len=%d n, nn); if(strcmp(s1, s2) == 0) printf( 等しい n ); if(strcmp(s1, s2)!= 0) printf( 等しくない n ); < 文字列の長さを求める > strcat(s1, s2); printf( s1+s2=%s n,s1); n=strlen( 文字列 もしくは文字列変数 ); if(strcmp(s1, s1 s2) [0] > 0) [1] [2] [3] [4] return [5] 0; [6] [7] [8] [9] printf( 左辺が大 n ); } if(strcmp(s1, s2) a< 0) b c d e 0 printf( 右辺が大 n ); 5

文字列の操作 - 具体例を通して (141 ページ ) #include <stdio.h> #include <string.h> < 文字列の比較 > strcmp( 文字列 1 文字列 2); int main(void) { char s1[80],s2[80]; int nn; if(strcmp(s1,s2)==0) if(strcmp(s1,s2)!=0) if(strcmp(s1, abcde )==0) if(strcmp(s1, FGHIJ )!=0) strcpy(s1, abcde ); strcpy(s2, FGHIJ ); printf( s1=%s s2=%s n,s1,s2); nn=strlen(s1); printf( len=%d n, nn); if(strcmp(s1, s2) > 0) printf( 左辺が大 n ); if(strcmp(s1, s2) < 0) printf( 右辺が大 n ); } if(strcmp(s1, s2) == 0) printf( 等しい n ); if(strcmp(s1, s2)!= 0) printf( 等しくない n ); strcat(s1, s2); printf( s1+s2=%s n,s1); return 0; 6

#include <stdio.h> #include <string.h> 文字列の操作 - 具体例を通して (141 ページ ) s1 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] a b c d e 0 F G H I J int main(void) { char s1[80],s2[80]; int nn; s2 [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] F G H I J 0 strcpy(s1, abcde ); strcpy(s2, FGHIJ ); printf( s1=%s s2=%s n,s1,s2); < 文字列の連結 > nn=strlen(s1); printf( len=%d n, nn); strcat( 文字列変数 連結する文字列 ); if(strcmp(s1, s2) == 0) printf( 等しい n ); if(strcmp(s1, s2)!= 0) printf( 等しくない n ); strcat(s1, s2); printf( s1+s2=%s n,s1); strcpy(s1, XYZ ); strcat(a, ABCDE ); if(strcmp(s1, s2) > 0) printf( 左辺が大 n ); if(strcmp(s1, s2) < 0) printf( 右辺が大 n ); } return 0; 7

文字列を扱う 数学関数を使う 8

数学関数を使う - 具体例を通して (146 ページ ) #include <stdio.h> #include <math.h> int main(void) { printf( sin 30=%f n, sin(30.0*3.14159/180.0)); printf( cos 30=%f n, cos(30.0*3.14159/180.0)); printf( tan 45=%f n, tan(45.0*3.14159/180.0)); printf( 2 の 3 乗 =%f n,pow(2.0,3.0); printf( 1000 の常用対数 =%f n,log10(1000.0)); printf( 10 の平方根 =%f n, sqrt(10.0)); } return 0; 9

数学関数を使う - 具体例を通して (146 ページ ) #include <stdio.h> #include <math.h> 数学関数を用いるときはつける ( と覚える ) int main(void) { printf( sin 30=%f n, sin(30.0*3.14159/180.0)); printf( cos 30=%f n, cos(30.0*3.14159/180.0)); printf( tan 45=%f n, tan(45.0*3.14159/180.0)); printf( 2 の 3 乗 =%f n,pow(2.0,3.0); printf( 1000 の常用対数 =%f n,log10(1000.0)); printf( 10 の平方根 =%f n, sqrt(10.0)); } return 0; サイン コサイン タンジェント sin(30.0 * 3.14159 / 180.0) cos(30.0 * 3.14159 / 180.0) tan(45.0 * 3.14159 / 180.0) 10

数学関数を使う - 縁がないと思ったら大間違い (x,y) 11

数学関数を使う - 縁がないと思ったら大間違い (x,y) m 12

数学関数を使う - 縁がないと思ったら大間違い m sinθ (x,y) m m θ m cosθ 13

数学関数を使う - 縁がないと思ったら大間違い (x,y) (x,y ) m sinθ m θ m cosθ x = x + m cosθ y = y + m sinθ 14

代表的な数学関数 サイン sin x sin(x); コサイン cos x cos(x); タンジェント tan x tan(x); 累乗値 x y pow(x,y); 常用対数 log 10 x log10(x); 平方根 x sqrt(x); 15

数学関数を使う - 具体例を通して (146 ページ ) #include <stdio.h> #include <math.h> int main(void) { printf( sin 30=%f n, sin(30.0*3.14159/180.0)); printf( cos 30=%f n, cos(30.0*3.14159/180.0)); printf( tan 45=%f n, tan(45.0*3.14159/180.0)); printf( 2 の 3 乗 =%f n,pow(2.0,3.0); printf( 1000 の常用対数 =%f n,log10(1000.0)); printf( 10 の平方根 =%f n, sqrt(10.0)); } return 0; 16

数学関数を用いるときの注意 1. 三角関数を使うとき 角度はラジアンで表現する! ラジアン : 角度を表す単位 0 度 =0 ラジアン 180 度 =3.14159 ラジアン ( つまり円周率 π ラジアン ) 360 度 =6.28318 ラジアン ( つまり 2π ラジアン ) では任意の角度 X 度は? X/180.0*3.14159 ラジアン 2. 数学関数は引数も戻り値も double 型! double 型戻り値 = func(double 型の引数 ); double 型戻り値 = func(double 型の引数,double 型の引数 ); 17

文字列を扱う 数学関数を使う その他 18

その他 入出力用の関数 putchar(), getchar(), puts(), gets(), printf(), scanf() ファイル入出力用の関数 fopen(), fclose(), fputc(), fgetc(), fputs(), fgets(), fprintf(), fscanf() ( 詳細については次章で扱う ) 19

その他 文字処理用関数 isalnum(c), isalpha(c), isdigit(c), islower(c), isupper(c), isxdigit(c), tolower(c), toupper(c) #include <stdio.h> #include <string.h> #include <ctype.h> int main(void) { int i,n; char s1[80]; < プログラム例 > 文字列 s1 内の文字を全て大文字に変換する } strcpy(s1,"abcdefghijklmn"); n=strlen(s1); for(i=0;i<n;i++) s1[i]=toupper(s1[i]); printf("%s n",s1); return 0; 20