NTU-Exam 板


LINE

课程名称︰计算机程式设计 课程性质︰系定必修 课程教师︰丁培毅 开课学院: 开课系所︰数学系 考试日期(年月日)︰97年11月10日 考试时限(分钟):120分钟 是否需发放奖励金:是 (如未明确表示,则不予发放) 试题 : I. Please correct possible errors and/or fill in the missing expression in the following program (18) 01#include <stdio.h>; 02int main(void); 03{ 04 int b; c; 05 int status; 06 do 07 { 08 error = 0; 09 printf('Please input two positive number 10 (with the first one less than the second) :'); 11 status = scanf("%d %d", b, c) 12 if(status = 2) 13 { 14 / * Validity check * / 15 if (b < 0 || c < 0) 16 error = 1; 17 printf("Input numbers (%d, %d) are" 18 "negative\n", b, c); 19 } 20 else if(b > c) 21 printf("Order is incorrect.\n"); 22 }while error; 23 24 b = sum(b, c); 25 print("The sum is %f\n", b); 26 return; 27} 28 29int sum(int num1, num2) 30{ 31 int summation; 32 int num1; 33 int num2; 34 num1 + num2 = summation; 35 Return summation; 36} II. Basic program development 1. What are the five steps of the software development method to slove a programming problem? (5) 2. What is the basic language construct to achieve "Modular Programming" in a C program? (3) 3. Why do you need to define variable in a C program (e.g. double number;)? (6) Also, why do you need to specify its type (e.g. double)? (6) 4. When do you need to define a variable as an integer (e.g. int x;) and when do you need to define a variable as a floating point number (e.g. double x;) (6, please address the representation accuracy, range and the computation issues) 5. When do you consider using a "counting for loop" instead of a general "while loop"? (6) III. Program writing (30) 1. Assume that we have a function "double myrand(void);" that returns a random number uniformly distributed in [0,1) upon each call, please write a function "int toss(void);" that simulates a crooked dice and returns a random integer representing the number of pips. The probability masses of each pips are shown in the following table: ╔═════════╤═══╤═══╤═══╤═══╤═══╤═══╗ ║ Pips │ 1 │ 2 │ 3 │ 4 │ 5 │ 6 ║ ╟─────────┼───┼───┼───┼───┼───┼───╢ ║ Probability mass │ 1/3 │ 1/4 │ 1/6 │ 1/12 │ 1/12 │ 1/12 ║ ╚═════════╧═══╧═══╧═══╧═══╧═══╧═══╝ 2. Please design a driver program using the "switch statement" to test the above function (Hint: use a loop to run many times, accumulate the results' relative occurrence frequency, and print out the difference with the above.) IV. Program reading (Please explain the hign level purpose and algorithm of the following function and replace the first "while loop" with a "for loop")(20) 01double func(double x, int y) 02{ 03 double p; 04 p = 1.0; 05 if(y>0) 06 while(y>0) 07 { 08 p *= x; 09 y--; 10 } 11 else 12 while(y<0) 13 { 14 p /= x; 15 y++; 16 } 17 return p; 18} V. Program desk checking 1. Please simulate the execution of the following expressions: show me the sequence of each operator and tell me the intermediate results of each operations (10) a. 4 / 3 * 1.5 - 1.2 * -1 > 1.8 b. fabs(-7) note: double fabs(double); 2. How many lines does the following program segment print out? (show me the detailed analysis) (10) for(i=0; i<5; i++) for(j=0; j<i; j++) if((i+j)%2) printf("%d %d\n", i, j); --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.136.9.109







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP