作業系統
DESCRIPTION
作業系統. 老師 :李冠憬 助教:楊斯竣. 大綱. scanf () switch 試 做 for while do….while 試 做. scanf (). 格式: scanf (“ 格式字串 ”,& 變數 1,& 變數 2,…);. scanf (). 請設計讓使用者輸入 兩數相加, 顯示兩數 相 加 的 結果, ( 請宣告兩個變數去顯示 ) 。. scanf (). 請設計讓使用者輸入十六進位轉十進位,顯示轉換的結果 ( 請 宣告變數 去 顯示,注意變數宣告方式 ) 。. scanf (). - PowerPoint PPT PresentationTRANSCRIPT
Providence University
1/5Dept. of Computer Science and Information Engineering 資訊工程學系
作業系統
老師:李冠憬助教:楊斯竣
Providence University
2/5Dept. of Computer Science and Information Engineering 資訊工程學系
大綱• scanf()• switch• 試做• for• while• do….while• 試做
Providence University
3/5Dept. of Computer Science and Information Engineering 資訊工程學系
scanf()
• 格式:scanf(“格式字串” ,&變數 1,&變數 2,…);
輸入格式 輸入敘述 輸入格式 輸入敘述
%c 字元 %s 字串
%d 十進位整數 %o 八進位整數
%f 浮點數 %x 十六進位整數
%lf 倍精度浮點數 (注意 %lf裡的 l是英文小寫字母 l)
Providence University
4/5Dept. of Computer Science and Information Engineering 資訊工程學系
scanf()
• 請設計讓使用者輸入兩數相加,顯示兩數相加的結果, (請宣告兩個變數去顯示 )。
Providence University
5/5Dept. of Computer Science and Information Engineering 資訊工程學系
scanf()
• 請設計讓使用者輸入十六進位轉十進位,顯示轉換的結果 (請宣告變數去顯示,注意變數宣告方式 )。
Providence University
6/5Dept. of Computer Science and Information Engineering 資訊工程學系
scanf()
• 請設計讓使用者輸入一字元,顯示其 ASCII碼,顯示結果 (請宣告變數去顯示,注意變數宣告方式 )。
Providence University
7/5Dept. of Computer Science and Information Engineering 資訊工程學系
switch
• 格式:switch(運算式 )
{
case 選擇值 1:
敘述主體 ;
break;
case 選擇值 2:
敘述主體 ;
break;
…..
default:
敘述主體 ;
}
運算式可以是整數或字元
Providence University
8/5Dept. of Computer Science and Information Engineering 資訊工程學系
試做• 請寫出一程式讓使用者輸入運算式,顯示其運算結果,如下圖。
Providence University
9/5Dept. of Computer Science and Information Engineering 資訊工程學系
試做• 請寫一個程式讓使用者輸入 1~12數字顯示其月份英文,顯示如下圖。
Providence University
10/5Dept. of Computer Science and Information Engineering 資訊工程學系
for
• 格式:for(設定迴圈初始值 ;判斷條件 ;設定增減量 )
{
迴圈主體 ;
}
Providence University
11/5Dept. of Computer Science and Information Engineering 資訊工程學系
試做• 用 for迴圈寫出 1~10的加總。
Providence University
12/5Dept. of Computer Science and Information Engineering 資訊工程學系
while
• 格式:設定迴圈初始值while(判斷條件 )
{
迴圈主體 ;
設定增減量 ;
}
Providence University
13/5Dept. of Computer Science and Information Engineering 資訊工程學系
試做• 用 while迴圈寫出 1~10的加總。
Providence University
14/5Dept. of Computer Science and Information Engineering 資訊工程學系
do…while
• 格式:設定迴圈初始值do
{
迴圈主體 ;
設定增減量 ;
}while(判斷條件 );
Providence University
15/5Dept. of Computer Science and Information Engineering 資訊工程學系
試做• 用 do…while迴圈寫出 1~10的加總。
Providence University
16/5Dept. of Computer Science and Information Engineering 資訊工程學系
試做• 分別用 for、 while、 do…while做出九九乘法表。