電卓プログラム流れ図の例
DESCRIPTION
開始. 数字 , 記号 , 数字 の入力. no. no. no. no. 記号 = +. 記号 = -. 記号 = *. 記号 = /. yes. yes. yes. yes. 足し算. 引き算. 掛け算. 割り算. 答え表示. エラー表示. 終了. 電卓プログラム流れ図の例. if 文も switch 文も 同じでよい. 電卓プログラム例 1 if 文. else if(kigo=='-') { c=a-b; printf("%d - %d = %d\n",a,b,c); } - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 電卓プログラム流れ図の例](https://reader035.vdocuments.pub/reader035/viewer/2022072109/56812b99550346895d8fba98/html5/thumbnails/1.jpg)
電卓プログラム流れ図の例
引き算
開始
終了
数字 , 記号 , 数字の入力
記号 = +
答え表示
記号 = - 記号 = * 記号 = /
掛け算 割り算足し算
エラー表示
yes
no
yes yes yes
no no no
if 文もswitch 文も同じでよい
![Page 2: 電卓プログラム流れ図の例](https://reader035.vdocuments.pub/reader035/viewer/2022072109/56812b99550346895d8fba98/html5/thumbnails/2.jpg)
/*a601081*/#include <stdio.h>main(){int a,b,c;char kigo,d;printf("Enter 1st integer : ");scanf("%d",&a);printf("Enter Sign(+,-,*,/) : ");scanf("%c%c",&d,&kigo);printf("Enter 2nd integer : ");scanf("%c%d",&d,&b);if(kigo=='+'){c=a+b;printf("%d + %d = %d\n",a,b,c);} 右上に続く
else if(kigo=='-'){c=a-b;printf("%d - %d = %d\n",a,b,c);}else if(kigo=='*'){c=a*b;printf("%d * %d = %d\n",a,b,c);}else if(kigo=='/'){c=a/b;printf("%d / %d = %d\n",a,b,c);}else{printf("The sign is wrong!\n");}}
電卓プログラム例 1 if 文
![Page 3: 電卓プログラム流れ図の例](https://reader035.vdocuments.pub/reader035/viewer/2022072109/56812b99550346895d8fba98/html5/thumbnails/3.jpg)
/* a601059 */#include <stdio.h>main(){
int m,n,x;char kigo,dummy;scanf("%d",&m);scanf("%c%c",&dummy,&kigo);scanf("%c%d",&dummy,&n);if(kigo=='+')x=m + n;else if(kigo=='-')x=m - n;else if(kigo=='*')x=m * n;else if(kigo=='/')x=m / n;printf(" %d %c %d = %d \n",m,kigo,n,x);
}
電卓プログラム例 2 if 文
![Page 4: 電卓プログラム流れ図の例](https://reader035.vdocuments.pub/reader035/viewer/2022072109/56812b99550346895d8fba98/html5/thumbnails/4.jpg)
/*A601130*/#include<stdio.h>main(){ int x,y,z; char a; printf(" キラササシー、 ホマ、キ、ニイシ、オ、、。」 :"); scanf("%d %c %d",&x,&a,&y); if(a=='+') z=x+y; else if(a=='-') z=x-y; else if(a=='*') z=x*y; else z=x/y; printf("%d%c%d=%d\n",x,a,y,z);}
電卓プログラム例 3 if 文
![Page 5: 電卓プログラム流れ図の例](https://reader035.vdocuments.pub/reader035/viewer/2022072109/56812b99550346895d8fba98/html5/thumbnails/5.jpg)
/*a601146*/#include <stdio.h>main(){ int a,b,d,x; char c; printf(" 妤・ ソ 、 ニ、ッ、タ、オ、、 : "); scanf("%d",&a); printf(" 讀 ホホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホ ホオュケ ホマ、キ、ニイシ、オ、、。」。ハマツ =+ ホ ホ =- タム =* セヲ =/ ホホ : "); scanf("%c%c",&x,&c); printf(" 妤・ ソ 、 ニイシ、オ、、 : "); scanf("%c%d",&x,&b); switch(c) { case '+': printf(" %d + %d = %d \n" ,a,b,a+b); break; case '-': printf(" %d - %d = %d \n" ,a,b,a-b); break; case '*': printf(" %d * %d = %d \n" ,a,b,a*b); break; case '/': printf(" %d / %d = %d \n" ,a,b,a/b); break; default :printf(" 讀 オュケ ャノヤナャタレ、ヌ、ケ。」 \n");} }
電卓プログラム例 4 switch 文
![Page 6: 電卓プログラム流れ図の例](https://reader035.vdocuments.pub/reader035/viewer/2022072109/56812b99550346895d8fba98/html5/thumbnails/6.jpg)
Newton 法の流れ図の例
“if 文 + 繰り返し”はfor (繰り返し回数が 分かっている場合)、while (繰り返し回数が 分かっていない場合) で何とかなります。
数字 a の入力
開始
|x0 -x1| → error
error>EPS終了
a→x0
答え x1
yes no
x1→x0
x0 -f(x0)/f’(x0) → x1
EPS は許容誤差
例: 0.0001
平方根を求める場合 f(x) = x2 -a f’(x) = 2 * x