天津理工大学c语言上机报告3,天津理工大学-c语言上机报告4.pdf
實驗四
(2009-9-24 )
一、實驗名稱:
程序控制結構。
二、實驗目的:
(1) 掌握C 語言基本程序結構(順序、分支和循環)及其應用;
(2) 結合程序理解一些常用的算法(窮舉、迭代和遞推等);
(3) 進一步熟悉Visual C++6.0 開發環境下調試程序的基本步驟。
三、實驗項目
(1)
源程序:
#include
int main()
{
int x;
int y;
//輸入(Input )
printf("Enter an integer: \n");
scanf("%d", &x);
//處理(Process )
if(x<1)
y=x;
else if(x<6)
y=3*x-2;
else
y=4*x-8;
//輸出(Output )
printf("y=%d\n", y);
return 0;
}
(2)
1
采用 if 語句時,源程序為:
#include
int main()
{
int score;
//輸入(Input )
printf("Enter the score: \n");
scanf("%d", &score);
//處理(Process )和輸出(Output )
if(score>100||score<0)
printf("Illegal\n");
else if(score>=90)
printf("Excellent\n");
else if(score>=80)
printf("Good\n");
else if(score>=70)
printf("Middle\n");
else if(score>=60)
printf("Passed\n");
else
printf("Failed\n");
return 0;
}
采用 swtich 語句時,源程序為:
#include
int main()
{
int score;
//輸入(Input )
printf("Enter the score: \n");
scanf("%d", &score);
//處理(Process )和輸出(Output )
switch(score/10)
{
case 10:
case 9:
printf("Excellent\n");
break;
case 8:
總結
以上是生活随笔為你收集整理的天津理工大学c语言上机报告3,天津理工大学-c语言上机报告4.pdf的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 速度与稳定并存!8G内存条霸气登场
- 下一篇: 游戏玩家必看:升级ddr4内存,游戏体验