NTUBIME96-HW 板


LINE

【第一题】 1. True 2. False 3. False 4. True 5. True 【第二题】 a = 8192 b = 30 【第三题】 ****** ****** ****** ****** ****** ****** ****** ****** ****** 【第四题】 b=9 b=25 b=57 b=121 b=249 【第五题】 // Problem 5 #include "stdafx.h" #include <iostream> using std::cin; using std::cout; using std::endl; void main(void) { float s = 0.0; int n; cout << "Please give the number of terms in the S series\n"; cin >> n; // Get the number of terms for( int i=1; i<=n; i++) // Calculate the S series { s = s + 1.0/i/i; } cout << "S = " << s << endl; // Output the result } 【第六题】 x=2 x=4 x=8 x=16 x=32 【第七题】 // Problem 7 #include "stdafx.h" #include <iostream> #include <iomanip> using std::cout; using std::endl; using std::setw; void main(void) { for( int i=1; i<=9; i++) { for( int j=1; j<=9; j++) { cout << i << '*' << j << '=' << setw(2) << i*j << ' '; } cout << endl; } } 【第八题】 //Problem 8 #include <iostream> #include "conio.h" // using for getch() . using std::cout; using std::cin; using std::endl; void find(int N); //自订的找出整数N之内所有质数的函式(不传回值). void main() { int N; cout << "本程式之功能是让使用者找出整数1至N之间的质数" << endl; cout << "请输入 N = "; cin >> N; cout <<"=====================================" "=====================================" << endl; find(N); //呼叫自行定义的函式找出质数并且做cout. cout << "\nPress any key to continue...\n"; getch(); //使画面暂留. } void find(int N) { int nflag=0; //nflag代表每个数的因数的数目. for(int n=1;n<=N;n++) { for(int i=1;i<=n;i++) { if(n%i==0) nflag++; //每当一个数被除余零时,其因数数目nflag加1. } if(nflag<=2) //if判断.若是nflag小於等於2,表其因数只有1与本//身,则其为质数. cout << n << "\t"; //将结果输出并以一个tab间隔. nflag=0; //将nflag归零,再做下一个数的计算. } } 【第九题】 //Problem 9 #include <iostream> #include "conio.h" // using for getch(). #include <ctime> // using for time(). using std::cout; using std::cin; using std::endl; int loto_number(); //自行定义的乐透随机选取函式. int Num1, Num2, Num3, Num4, Num5, Num6, NumS; //宣告七个整数型态,代表六个号码以及一个特别号. void main() { srand( time(0) ); // randomize by time. Num1=loto_number(); //开始产生六个号码以及特别号. Num2=loto_number(); Num3=loto_number(); Num4=loto_number(); Num5=loto_number(); Num6=loto_number(); NumS=loto_number(); cout << "本期乐透彩开奖的六个号码是:\n" ; printf("%d\t%d\t%d\t%d\t%d\t%d\n", Num1, Num2, Num3, Num4, Num5, Num6); // %d表整数型态 , \t 表tab之跳脱字元。用cout输出亦可. cout << "特别号是:" << NumS << endl << endl; cout << "下次再会..."; getch(); //将画面停格. } int loto_number() { int number; do //从1~42随机选取一个数字 number=1+ rand()%42;//若是和Num1~6或NumS重复,则重选一个. while ( (number== Num1) || (number== Num2) ||(number== Num3) ||(number== Num4) ||(number== Num5) || (number== Num6) || (number== NumS)); return number; //将随机选出的数字传回 --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.7.59
1F:→ gippholugan:好棒! 推 219.91.9.68 11/19
2F:→ kaidou848:推推 推 61.216.12.175 11/20







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灯, 水草

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

TOP