506.
設計說明:
1. 此程式為計算圓的面積。
2. 修改程式碼片段中的程式語法、邏輯上的錯誤,執行結果如範例圖。
參考程式碼:
TQC+ C 試題總整理
- struct circle {
 - int x, y;
 - double radius;
 - };
 - double callarea(struct circle *pr);
 - #include <stdio.h>
 - #include <stdlib.h>
 - int main ()
 - {
 - double area;
 - struct circle c1={10, 10, 8.5};
 - area = callarea(&c1);//補上&參照
 - printf("此圓的圓心為(%d, %d), 半徑為%.2f, 面積為%.2f\n", c1.x, c1.y, c1.radius, area);//radius是宣告在callarea裡面
 - system("PAUSE");
 - return 0;
 - }
 - double callarea(struct circle *pr)//宣告的形態要一致,改成double
 - {
 - double area;//一併改成double
 - area = pr->radius * pr->radius * 3.14159;
 - return area;
 - }
 
TQC+ C 試題總整理
聲明:
這裡的範例程式碼皆由本人親自編輯,歡迎轉載本教學,但請註明本網站,尊重一下作者的心血
沒有留言:
張貼留言
歡迎留言,較舊文章需要留言審核看不到自己的留言是正常的。
若長時間無回應請使用以下聯絡方式:
填寫表單:https://forms.gle/hxxX9n4tATcFnhnk8
寄信到:happyplayblogs@gmail.com