Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 Introduction to compilation process March 24

2 The following slides will show you step by step instruction how to get ready and build C language programs in Linux Ubuntu. 2 1.Enter terminal by pressing 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 typing nano first.c

3 nano editor 3 See the control option at the bottom of the screen. For example to delete line of text press k

4 Type your program 4 Important!!! Add comments Add indents

5 Building the program 5 To build(create a binary file) your program type gcc -o build execute

6 Errors 6 Remove ; Remove & Lets make an error and a warning on purpose

7 Building a program with errors 7 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.

8 Largest of three numbers 8 start read X, Y, Z stop X > Y ? stop yesno max > Z ? Output max Output z yesno Max = XMax = Y Transform the flowchart below to a C language program. See next slide

9 Largest of three numbers 9

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 10 start read x stop x % 2 == 0 ? stop yesno Output “even” Output “odd”

11 Find whether a number is odd or even Type the program in nano editor and compile it with gcc evenodd.c -o evenodd 11

12 Example of a while loop The program prints out a conversion table from Fahrenheit to Celsius. Draw a corresponding flowchart 12 Program Output

13 13 start read N stop Count > N ? output sum no yes sum = sum + count * count sum = 0 count = 1 count = count + 1 Example of a for loop The program calculates the following sum: sum = 1 2 + 2 2 + 3 2 + … + N 2

14 The following slides are your homework assignments 14

15 15 start read N stop Count > N ? output sum no yes sum = sum + count * (count + 1) sum = 0 count = 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

16 16 start read N stop count > N ? output sum no yes prod = prod * count prod = 1 count = 1 count = count + 1 Problem 2 Convert to C program Use for() loop construction The following algorithm calculates factorial

17 17 start Read X, N stop count > N ? output sum no yes sum = prod * count term = term * X / count term = 1 prod = 1 count = 1 count = count + 1 Problem 3 Use Taylor expansion to represent e x up to N terms. Convert to C program Hint: Use for() loop construction The following algorithm computes e x series up to N terms

18 18 start Read X, N stop term <.0001 ? output sum no yes sum = prod * count term = term * X / count term = 1 prod = 1 count = 1 count = count + 1 Problem 4 Use Taylor expansion to represent e x up to 4 decimal places. Convert to C program Hint: Use do{}while() loop construction The following algorithm computes e x series up to 4 decimal places


Download ppt "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."

Similar presentations


Ads by Google