二进位也可以很有趣.ppt

二进位也可以很有趣

Programming Concept 蔡文能 tsaiwn@.tw 交通大學資訊工程學系 程式 隨便寫 隨便對? 蔡文能 tsaiwn@.tw 交通大學資訊工程學系 印出根號 2 /* 寫個程式印出根號2 */ #includestdio.h double sqrt(double); // #includemath.h int main( ) { printf( sqrt 根號 2 =%f\n , sqrt(2.0) ); // C++ 式的註解 comment printf(Bye bye!\n); return 0; } 印出根號 3 /* 寫個程式印出根號3 */ #includestdio.h double sqrt(double); // #includemath.h int main( ) { printf( sqrt 根號 3 =%f\n , sqrt(3.0) ); // C++ 式的註解 comment printf(Bye bye!\n); return 0; } 印出根號 x /* 寫個程式印出根號 x */ #include stdio.h #includemath.h double y; int main( ) { printf( Give me x : ); scanf(%lf , y); printf(Sqrt(%f)=%f\n, y, sqrt(y) ); return 0; } 程式 隨便寫 求 x 的平方根 蔡文能 tsaiwn@.tw 交通大學資訊工程學系 p3.c – 練習 while loop #include stdio.h #include math.h int main() /* This program can find square root of any number that =0 and will stop when you enter a value that 0 阿版權是蔡文能的, 歡迎拷貝分享初學者! */ { float onevar; /* 變數名稱隨便我取的啦 */ double ans; /* 用來放答案 */ printf(Find square root of X. Negative value will cease the program\n); printf(X=? ); /* 還是問X=? 比較簡潔有力, 不用說onevar */ scanf(%f, onevar); while(onevar =0 ) { /*只要onevar大於或等於零我們就一直重複做{...} */ ans=sqrt(onevar); /*其實sqrt的參數也應該為double 型別*/ printf( SQRT(%f)=%f\n, onevar, ans); printf(X=? ); scanf(%f, onevar); } /* while(onevar */ return 0; } 程式 隨便寫 求 x 的平方根 p4.c – 練習 想 Algorithm(1/2) /* This program can find square root of any number that =0 and will stop when you enter a value that 0 */ /* This version is trying to show you that we can write our function/procedure to solve the problem, though the mysqrt() is actually calling the system standard function. We will rewrite the mysqrt() in next version. *****************************/ void hello(void); /*我會用到一個沒參數的函數叫hello() */ double mysqrt(double); /*也會叫用一個叫mysqrt()的函數,參數是一個double數 */ #include math.h /* sqrt()是在math.h內宣告的 */ int main()

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档