1 / 15

Introduction to C Programming

Introduction to C Programming. HOMEWORK 2. Homework 2-1 :三角形. 說明 練習利用 For-loop 來畫出 20×20 的直角三角形 Sample input none Sample output. Homework 2-2 :三角形動畫. 說明 練習利用 For-loop 來畫出 20×20 的直角三角形 利用 sleep 、 system(“ clr ”) 來畫一個會從 左至右每秒移動一 格、總共執行時間 10 秒 Sample input none Sample output (如下頁動畫所示).

dinesh
Download Presentation

Introduction to C Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to C Programming HOMEWORK 2

  2. Homework 2-1:三角形 • 說明 • 練習利用For-loop來畫出20×20的直角三角形 • Sample input • none • Sample output

  3. Homework 2-2:三角形動畫 • 說明 • 練習利用For-loop來畫出20×20的直角三角形 • 利用sleep、system(“clr”)來畫一個會從左至右每秒移動一格、總共執行時間10秒 • Sample input • none • Sample output • (如下頁動畫所示)

  4. Homework 2-2:三角形動畫

  5. Homework 2-2 Tips • 我們已經在iLMS提供一個利用sleep、system(“clr”) 等函式,產生一個從10每秒逐次倒數到0的範例程式碼,請修改該程式碼來實作2-2的作業。 • 註: • 由於此兩函式在Windows上和在UNIX上使用方式不同,若是使用Windows的同學請下載hw2-2-windows-sample.c的範例、使用工作站等UNIX環境的同學請下載hw2-2-unix-sample.c的範例

  6. Homework 2-3:動畫小時鐘 • 說明 • 實作一個會動的小時鐘,每秒都會更新現在的時間 • Sample input • none • Sample output • (如下頁動畫所示)

  7. Homework 2-3:動畫小時鐘

  8. Homework 2-3 Tips • 我們已經在iLMS提供一個利用時間函式庫所提供的函式,可以產生一個顯現現在時間為何的範例程式碼,請修改該程式碼來實作2-3的作業。 • 有關time.h的使用,可參考下述網站: • http://www.acm.uiuc.edu/webmonkeys/book/c_guide/2.15.html

  9. Homework 2-4:最大公因數(gcd) • 說明 • 使用者輸入兩個數字,回傳兩者的最大公因數 • 需寫出使用while_loop(用while或do_while實作皆可)和for_loop的版本 • Sample input 4 26 • Sample output 2

  10. Homework 2-5:費氏數列 • Fibonacci Sequence • 所謂的FibonacciSequence是一個以遞迴方式定義的數列,其定義如下 • Fib(0)=0 • Fib(1)=1 • Fib(n)=Fib(n-1)+Fib(n-2) • 其數列由小到大依序如下(擷取Fib(0)~Fib(10)) 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55,…

  11. Homework 2-5:費氏數列 • 說明 • 利用for_loop或while_loop實作費氏數列 • 使用者輸入要計算的費氏數列個數(必大於兩項) • Sample input 50 • Sample output 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025

  12. Deadline • 10/18

More Related