|
1
|
- Instructor: Brian M. Dennis
- Teaching Assistants:
- Tom Lechner, Bin Lin
- http://www.cs.northwestern.edu/~bmd/cs211/
|
|
2
|
- #include <iostream>
- using namespace std;
- // HelloWorld programs originated with the
- // book “The C Programming Language”
- main() {
- cout << “Hello, World\n”;
- }
|
|
3
|
- ;; HelloWorld programs originated with the
- ;; book “The C Programming Language”
- (display “Hello World”)
- (newline)
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
- #include <iostream>
- using namespace std;
- main() {
- cout << “The answer to the universe\n”
- << 42;
- }
|
|
9
|
- #include <iostream>
- using namespace std;
- main() {
- cout << “Pi is: “ <<
3.14159f << “\n”;
- }
|
|
10
|
- #include <iostream>
- using namespace std;
- main() {
- cout << “1 + 1 = “ <<
1 + 1 << “\n”;
- cout << “2 * 2 = “ <<
2 * 2 << “\n”;
- cout << “3 – 5 = “ <<
3 – 5 << “\n”;
- cout << “11 / 2 = “
<< 11 / 2 << “\n”;
- }
|
|
11
|
- #include <iostream>
- using namespace std;
- main() {
- if ((10 % 2) == 0)
- cout << “10 is even\n”;
- if (5 % 2)
- cout << “5 is odd\n”;
- if ((5 % 2) != 0)
- cout << “5 is odd\n”;
- }
|
|
12
|
- #include <iostream>
- using namespace std;
- main() {
- int integer_temp = 1 + 1;
- cout << “1 + 1 = “ <<
integer_temp << “\n”;
- float floating_point_temp;
- floating_point_temp = 1.414f;
- cout << “Root 2 = “
<< floating_point_temp
- << “\n”;
- }
|
|
13
|
- (let ((integer_temp (+ 1 1))
- (floating_point_temp 1.414))
- (display “1 + 1 = “)
- (display integer_temp)
- (newline)
- (display “Root 2 = “)
- (display floating_point_temp)
- (newline)
- )
|
|
14
|
- (let ((temp (+ 1 1)))
- (display “1 + 1 = “)
- (display temp)
- (newline)
- (set! temp 1.414)
- (display “Root 2 = “)
- (display temp)
- (newline)
- )
|
|
15
|
- #include <iostream>
- using namespace std;
- main() {
- int temp = 1 + 1;
- cout << “1 + 1 = “ <<
temp << “\n”;
- temp = 1.414;
- cout << “Root 2 = “
<< temp << “\n”;
- }
|
|
16
|
|