C-programing- Note 12 - Note 12 PDF

Title C-programing- Note 12 - Note 12
Author Alina Siddique
Course C Programming
Institution University of Houston-Clear Lake
Pages 6
File Size 137 KB
File Type PDF
Total Downloads 77
Total Views 172

Summary

Note 12...


Description

CSCI 1320 C Programming

Class Notes (10/13/2020)

Last time: Basics of Looping Today: Review for the midterm exam Time: Thursday, Oct. 15 (8:30am-9:50am) Format: Take home exam The midterm exam questions will be posted in the Blackboard discussion board by 8:30am this Thursday. Send your answers as a Word file to [email protected]. Advice: Make sure you fully understand everything covered in the class notes. 

Components of a computer system: cpu (arithmetic and logic processing), primary memory (RAM), secondary/auxiliary storage (e.g., disks), input devices, output devices



Memory buffer?



The process of solving a problem (from the given task/problem to the final product/solution)



The process of creating a working program (from the editor to the final product)



Binary numbering system, hexadecimal system



if else



nested if else statements



program design using flowcharts



program design using pseudocodes



how to define a function



how to use a function in a program



how to trace a given function



how to pass data when calling a function: parameter passing by values vs parameter passing by references/pointers



basic looping (using flowchart and pseudocode)

Type of questions: problem-solving kinds of questions

e.g., - trace a function call, trace a flowchart or a pseudocode, - define a function, or design a solution using a pseudocode or flowchart, - converting a pseudocode to a flowchart or a c code, or vice versa

A loop in a program consists of a block of statements that are continually executed until certain condition becomes false. That is, when the looping condition remains true, the loop will continue.

Begin

Components of a loop: 1. Initialization of the looping variable(s)

a = 100 2. The looping condition b = 222

False a > 0 && a < b True

Print “Bye ”

Print a, b 3. The body of the loop a a /2

End

4. Change(s) of the looping variable(s) in the body of the loop b b-a

Exercise: Write the flowchart as a C program, and test it.

Exercise: Trace this program. a 100 50

b 200 150

Screen Output 100 200 50 150

25 12 6 3 1 0  

125 25 125 113 12 113 107 6 107 104 3 104 103 1 103 103 Bye Each row in the above tracing table is called an iteration of the loop. && means the logical ‘and’.

NOTE: An int divided by another int produces an int (i.e., an integer division). 25/2  12 1/2  0 

An infinite loop is a loop that will never end, because the looping condition is always true.

Exercise: Design a function called printNumbers( ) that takes a positive integer as the parameter, and then print all the numbers 1, 2, …, up to the given integer. For example, printNumbers(5) will print out 1 2 3 4 5, while printNumbers(10) will print out 1 2 3 4 5 6 7 8 9 10. Draw a flowchart to show your design of such a function. printNumbers (N): 1. Initialization of the looping variable(s), commonly called the iterator Let i =1 2. The looping condition i b, then go to step 7. Add a to result. Add a to i. Go to step 3. return result

Next Time: The midterm exam...


Similar Free PDFs