4/11 Fri 00:49 |
- [pe1-1.c](必須)
変数 a と b に標準入力(キーボード)から値を読み込み,
それらの値を一度出力した後で,変数 ab に a と b の積を代入し,「? x ? = ?」(数の表示は小数点以下第2位まで)の形で結果を出力するプログラムの空白部分 (a) から (e) を埋めなさい。
(変数,四則演算,scanf と printf による入出力)
/* pe1-1.c: multiplication program */
#include <stdio.h>
int main()
{
double a, b, ab;
scanf("%lf%lf", [(a) ]);
printf("a: %f\n", [(b) ]);
printf("b: %f\n", [(c) ]);
[(d) ];
[(e) ];
return 0;
}
- [pe1-2.c](必須)変数 n に正の整数を読み込んで 1 + 2 + ... + n を求めるプログラムの空白部分 (a) から (e) を埋めなさい。
なお,このプログラムは n までの和を求める途中の過程も表示する。
(反復構造,合計を求めるアルゴリズム)
/* pe1-2.c: summation program */
#include <stdio.h>
int main()
{
[(a) ] i, n, sum;
printf("Enter integer.\n");
scanf([(b) ]);
sum = [(c) ];
for (i = 1; [(d) ]) {
sum += [(e) ]
printf("%d\t%d\n", i, sum);
}
return 0;
}
- [pea1-1.c]
変数 n に正の整数を読み込んで 1 + 1/2 + ... + 1/n を求めるプログラムを作りなさい。
(データ型)
|