Re: [問題] 問問各位高手
※ 引述《love228224 (老姜)》之銘言:
: 想問問大家看看
: 大家在做C的時候
: 一開始拿到一些限制條件
: 最先開始的做法是什麼
: 或者本來應該開始的做法
: 我想大家的方法都不盡相同
: 有沒有什麼思考邏輯上比較好的方向
: 本人很想學
: 想學得更好 更多
: 但不想偏了我的方向
: 想一開始就往對的方向走
: 在這邊請大家指教!
不知道你想問的是不是Top-down跟Buttom-up解題法
如果是的話推薦一本書
http://findbook.tw/book/9789864120949/basic
Top-down就是先寫大function->中function->一直往下深入到C提供的function
Top-down的寫法流程如下:
題目:
請完成下列程式
======================
請輸入姓名:Jim
請輸入數學成績:97
請輸入計概成績:92
請輸入英文成績:77
Jim的成績如下:
===================
數學: 97
計概: 92
英文: 77
-------------------
總分:266
平均:88.67
XXXXXXXXXXXXXXXX以下為程式寫作流程XXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
//pre:
//post:
int main(){
//讀入姓名與成績
//加總與平均
//印出結果
//回傳main正確執行
return 0;
}//end main
XXXXXXXXXXXXXXXXXXXXX 1 XXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
String Name;
int MathScore;
int CompScore;
int EngScore;
void ReadIn();
void Statistic();
void Show();
//pre:
//post:
int main(){
//讀入姓名與成績
ReadIn();
//加總與平均
Statistic();
//印出結果
Show();
//回傳main正確執行
return 0;
}//end main
XXXXXXXXXXXXXXXXXXXXX 2 XXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
String Name;
int MathScore;
int CompScore;
int EngScore;
int Sum;
float Avg;
void ReadIn();
void Statistic();
void Show();
//pre:include stdio.h,stdlib.h
//post:
int main(){
//讀入姓名與成績
ReadIn();
//加總與平均
Statistic();
//印出結果
Show();
//回傳main正確執行
return 0;
}//end main
//pre:include stdio.h,stdlib.h
//post:Name,MathScore,CompScore,EngScore
void ReadIn(){
//顯示"請輸入姓名:"
//存入變數Name中
//顯示"請輸入數學成績:"
//存入變數MathScore中
//顯示"請輸入計概成績:"
//存入變數CompScore中
//顯示"請輸入英文成績:"
//存入變數EngScore中
}//end ReadIn()
//pre:exists MathScore,CompScore,EngScore
//post:Sum,Avg
void Statistic(){
//加總數學,計概,英文成績
Sum=MathScore+CompScore+EngScore;
//平均
Avg=Sum/3.0;
}//end Statistic()
//pre:
//post:
void Show(){
//印出"Name的成績如下:"
printf("\n==========================\n");
//印出" 數學: MathScore"
//印出" 計概: CompScore"
//印出" 英文: EngScore"
printf("\n---------------------------\n");
//印出" 總分:Sum"
//印出" 平均:Avg"
}//end Show()
XXXXXXXXXXXXXXXXXXXXXXXXX 3 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
char Name[20];
int MathScore;
int CompScore;
int EngScore;
int Sum;
float Avg;
void ReadIn();
void Statistic();
void Show();
//pre:include stdio.h,stdlib.h
//post:
int main(){
//讀入姓名與成績
ReadIn();
//加總與平均
Statistic();
//印出結果
Show();
//回傳main正確執行
return 0;
}//end main
//pre:include stdio.h,stdlib.h
//post:Name,MathScore,CompScore,EngScore
void ReadIn(){
//顯示"請輸入姓名:"
printf("請輸入姓名:");
//存入變數Name中
scanf("%s",Name);
//顯示"請輸入數學成績:"
printf("請輸入數學成績:");
//存入變數MathScore中
scanf("%d",&MathScore);
//顯示"請輸入計概成績:"
printf("請輸入計概成績:");
//存入變數CompScore中
scanf("%d",&CompScore);
//顯示"請輸入英文成績:"
printf("請輸入英文成績:");
//存入變數EngScore中
scanf("%d",&EngScore);
}//end ReadIn()
//pre:exists MathScore,CompScore,EngScore
//post:Sum,Avg
void Statistic(){
//加總數學,計概,英文成績
Sum=MathScore+CompScore+EngScore;
//平均
Avg=Sum/3.0;
}//end Statistic()
//pre:exists Name,MathScore,CompScore,EngScore,Sum,Avg
//post:印出pre中所有值
void Show(){
//印出"Name的成績如下:"
printf("%s的成績如下:",Name);
printf("\n==========================\n");
//印出" 數學: MathScore"
printf(" 數學:%d\n",MathScore);
//印出" 計概: CompScore"
printf(" 計概:%d\n",CompScore);
//印出" 英文: EngScore"
printf(" 英文:%d\n",EngScore);
printf("\n---------------------------\n");
//印出" 總分:Sum"
printf(" 總分:%d\n",Sum);
//印出" 平均:Avg"
printf(" 平均:%f\n",Avg);
//暫停
system("pause");
}//end Show()
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.123.128.182
推
06/05 05:57, , 1F
06/05 05:57, 1F
討論串 (同標題文章)