Morse's ready reference dictionary : a handy compilation ...
Introduction to compilation process March 24. The following slides will show you step by step...
-
Upload
delphia-fleming -
Category
Documents
-
view
217 -
download
0
Transcript of Introduction to compilation process March 24. The following slides will show you step by step...
![Page 1: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/1.jpg)
Introduction to compilation process
March 24
![Page 2: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/2.jpg)
2
The following slides will show you step by step instruction how to get ready and build C language programs in Linux Ubuntu.
1. Enter terminal by pressing <ctrl> <alt> t
2. To create a folder workspace/programming in you home folder type
mkdir -p ~/workspace/programming/3. Enter newly created folder cd ~/workspace/programming/
4. Enter text editor by typingnano first.c
![Page 3: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/3.jpg)
3
nano editor
See the control option at the bottom of the screen.For example to delete line of text press <ctrl> k
![Page 4: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/4.jpg)
4
Type your programImportant!!!
Add comments
Add indents
![Page 5: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/5.jpg)
5
Building the program To build(create a binary file) your program typegcc <source_file.c> -o <binary_file>
buildexecute
![Page 6: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/6.jpg)
6
Errors
Remove ;
Remove &
Lets make an error and a warning on purpose
![Page 7: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/7.jpg)
7
Building a program with errors
Notifies us about the syntactical error
Notifies us about the warning
Even thought program compiles and ready to run, it will not function correctly, thus pay attention to warnings carefully.
![Page 8: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/8.jpg)
8
Largest of three numbers
start
read X, Y, Z
stop
X > Y ?
stop
yes no
max > Z ?
Output max Output z
yes no
Max = X Max = Y
Transform the flowchart below to a C language program.
See next slide
![Page 9: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/9.jpg)
9
Largest of three numbers
![Page 10: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/10.jpg)
10
Find whether a number is odd or even Draw a flow chart for the algorithm that checks whether the
number is odd or even. Convert the algorithm into C language program
start
read x
stop
x % 2 == 0 ?
stop
yes no
Output “even”
Output “odd”
![Page 11: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/11.jpg)
11
Find whether a number is odd or even Type the program in nano editor and compile it with
gcc evenodd.c -o evenodd
![Page 12: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/12.jpg)
12
Example of a while loop The program prints out a conversion table from Fahrenheit to
Celsius. Draw a corresponding flowchartProgram Output
![Page 13: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/13.jpg)
13
start
read N
stop
Count > N ?
output sum
no yes
sum = sum + count * count
sum = 0count = 1
count = count + 1
Example of a for loopThe program calculates the following sum: sum = 12 + 22 + 32 + … + N2
![Page 14: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/14.jpg)
14
The following slides are your homework assignments
![Page 15: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/15.jpg)
15
start
read N
stop
Count > N ?
output sum
no yes
sum = sum + count * (count + 1)
sum = 0count = 1
count = count + 1
Problem 1
Convert to C program
Use do{}while() loop construction
sum = 1*2 + 2*3 + 3*4 + … + N*(N +1)
The following algorithm calculates the sum
![Page 16: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/16.jpg)
16
start
read N
stop
count > N ?
output sum
no yes
prod = prod * count
prod = 1count = 1
count = count + 1
Problem 2
Convert to C program
Use for() loop construction
The following algorithm calculates factorial
![Page 17: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/17.jpg)
17
start
Read X, N
stop
count > N ?
output sum
noyes
sum = prod * countterm = term * X / count
term = 1prod = 1count = 1
count = count + 1
Problem 3
Use Taylor expansion to represent ex up to N terms.
Convert to C program
Hint: Use for() loop construction
The following algorithm computes ex series up to N terms
![Page 18: Introduction to compilation process March 24. The following slides will show you step by step instruction how to get ready and build C language programs.](https://reader036.fdocuments.us/reader036/viewer/2022062500/5697bfe11a28abf838cb40df/html5/thumbnails/18.jpg)
18
start
Read X, N
stop
term < .0001 ?
output sum
noyes
sum = prod * countterm = term * X / count
term = 1prod = 1count = 1
count = count + 1
Problem 4
Use Taylor expansion to represent ex up to 4 decimal places.
Convert to C program
Hint: Use do{}while() loop construction
The following algorithm computes ex series up to 4 decimal places