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

請輸入看板名稱,例如:iOS站內搜尋

TOP