本日の課題
2010.5.17

Back


1より大きく,2より小さい数2つを乱数を用いて準備し,それらの積と商を,以 下に示すように小数第3位までを実数表現と指数表現とでそれぞれ画面に表示す るプログラムを作成してください.

Obtained numbers are 1.838 and 1.698.
Product of them is 3.121 (3.121e+00).
Quotient of them is 1.082 (1.082e+00).

解答用紙


解答例

/* ************************************************** */
/*                                                    */
/*      情報科学演習 C6 C7                            */
/*      レポート課題                                  */
/*      2010.5.17                                     */
/*                                                    */
/* ************************************************** */
/*                                                    */
/*      学生番号:                                    */
/*                                                    */
/*      氏名:                                        */
/*                                                    */
/* ************************************************** */
/*                                                    */
/*      この行以降に解答のプログラムを書くこと        */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main()
{
	srand((unsigned) time(NULL));
	
	float chelsea, liverpool, arsenal, tottenham;
	
	chelsea = rand() % 999 / 1000.0 + 1.001;
	liverpool = rand() % 999 / 1000.0 + 1.001;
	
	arsenal = chelsea * liverpool;
	tottenham = chelsea / liverpool;
	
	printf("Obtained numbers are %1.3f and %1.3f.\n", chelsea, liverpool);
	printf("Product of them is %1.3f (%1.3e).\n", arsenal, arsenal);
	printf("Quotient of them is %1.3f (%1.3e).\n", tottenham, tottenham);
	
	return(0);

}


一覧ページに戻る