-
Notifications
You must be signed in to change notification settings - Fork 0
/
for_loop.cpp
57 lines (46 loc) · 1.03 KB
/
for_loop.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include<iostream>
using namespace std;
int main(){
//for( [A.]一開始先做什麼事 ; [B.]條件式 ; [D.]等C每作完一次,就做什麼事 ){
// [C.]當B條件成立時,就重覆做的事...
//}
//先做A ==> 檢查B條件,成立就做C,接著做D
//==> 檢查B條件,成立就做C,接著做D
//...
//==> 檢查B條件,成立就做C,接著做D
//==> 檢查B條件,不成立離開
//while迴圈
int index = 1 ;
int n ;
cout << endl << "input n : " ;
cin >> n ;
while( index <= n){
cout << "NO. " << index << endl ;
index = index + 1 ;
}
cout << "Equal to," << endl;
for(index = 1; index <= n; index = index + 1){
cout << "NO. " << index << endl ;
}
cout << "Equal to," << endl;
for(index = n; index >= 1; index = index - 1){
cout << "NO. " << n - index + 1 << endl ;
}
//原始寫法 簡寫
//i=i+1 i++
//i=i-1 i--
//a=a+b a+=b
//a=a-b a-=b
//a=a*b a*=b
//a=a/b a/=b
//a=a%b a%=b
//倒數計時
int i ,num ;
cout << "倒數計時, 輸入數字: " ;
cin >> num ;
for(i = num; i >= 1 ; i-- ){
cout << "Say: " << i << endl ;
}
cout << "Start!" ;
return 0;
}