1 / 6

電卓プログラム流れ図の例

開始. 数字 , 記号 , 数字 の入力. no. no. no. no. 記号 = +. 記号 = -. 記号 = *. 記号 = /. yes. yes. yes. yes. 足し算. 引き算. 掛け算. 割り算. 答え表示. エラー表示. 終了. 電卓プログラム流れ図の例. if 文も switch 文も 同じでよい. 電卓プログラム例 1 if 文. else if(kigo=='-') { c=a-b; printf(&quot;%d - %d = %d<br>&quot;,a,b,c); }

dana-king
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. 開始 数字,記号,数字 の入力 no no no no 記号 = + 記号 = - 記号 = * 記号 = / yes yes yes yes 足し算 引き算 掛け算 割り算 答え表示 エラー表示 終了 電卓プログラム流れ図の例 if 文も switch文も 同じでよい

  2. 電卓プログラム例 1if 文 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"); } } /*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); } 右上に続く

  3. 電卓プログラム例 2if 文 /* 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); }

  4. 電卓プログラム例 3if 文 /*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); }

  5. 電卓プログラム例 4 switch文 /*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"); } }

  6. Newton法の流れ図の例 “if文+繰り返し”は for (繰り返し回数が   分かっている場合)、 while (繰り返し回数が 分かっていない場合) で何とかなります。 開始 平方根を求める場合 f(x) = x2 -a f’(x) = 2 * x 数字 aの入力 a→x0 x0 -f(x0)/f’(x0) → x1 EPSは 許容誤差 例:0.0001 x1→x0 |x0 -x1| → error error>EPS 答えx1 終了 yes no

More Related