-
Notifications
You must be signed in to change notification settings - Fork 0
/
lec005.cpp
66 lines (52 loc) · 1.52 KB
/
lec005.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
58
59
60
61
62
63
64
65
66
//FOR LOOP
#include<iostream>
using namespace std;
int main() {
/*
// Bitwise Operators
int a = 4;
int b = 6;
cout<< "AND: a&b = " << (a&b) <<endl;
cout<< "OR: a|b = " << (a|b) <<endl;
cout<< "NOT: ~a = " << ~a <<endl;
cout<< "XOR: a^b = " << (a^b) <<endl;
// Bit Shifting
cout<< (17>>1) <<endl; //right shift (number is doubled)
cout<< (17>>2) <<endl; //right shift (number is doubled)
cout<< (19<<1) <<endl; //left shift (number is halved)
cout<< (21<<2) <<endl; //left shift (number is halved)
// Pre & Post increment/decrement
int i = 7;
cout<< (++i) <<endl;
// 8
cout<< (i++) <<endl;
// 8 , i=9
cout<< (i--) <<endl;
// 9 , i=8
cout<< (--i) <<endl;
// 7, i=7
*/
/*
for (int a=0, b=1; a<=10 && b<=20; a++, b++) { // for ({initial value/s}; {condition to run loop}; {increment or decrement}) {}
cout<< a << " " << b <<endl;
}
//Break and Continue also part of FOR loop
*/
//Fibonacci Sequence
/*
int steps;
cin>> steps;
int a = 0;
int b = 1;
cout<< a << " " << b << " ";
int nextNum;
for (int i=0; i<=steps; i++) {
nextNum = a + b;
cout<< nextNum << " ";
a = b;
b = nextNum;
}
*/
//If we redeclare a variable inside a condition, it will use the new variable as reference and vice versa
//If we declare a variable inside a condition, it can not be used outside
}