- CODEsign_2015
- c Test Questions)
- countfunctions
- c Program to Reverse an Array
- Mcsl 17 c Lab Manual
- Lesson 15 Array1
- All in One Maths Lab
- sr3
- Mcsl 17 c Lab Manual
- c Programs
- elab111
- C_C++
- APSC 160 (UBC)
- Input Output
- 139928164-C-Language
- Art_of_Programming_Contest_SE_for_uva.pdf
- Documentation on Analysis and Design
- 1292411593C Lect 1_Intro
- 0a
- ds prog
- Array
- Conditional Statements (Programming)
- C Command Line Arguments
- Cmp220hw
- Match Point
- Compre Closed Book
- Readme
- IBM SAMPLE PAPER1[Www.placementPapers.net]
- Introduction to C Programming
- C-programming notes
- 10 Differential Equation (Update)
- 5 Function of Two Variables
- Application of 1st Derivative
- Ece353 Notes
- 8 Extremum of Function
- 11 Applications of Separable Equations
- Technical Paper (Latest) - Fullllll
- 14 Applications of 2nd ODE [Read-Only]
- 12 Applications of Linear Equations
- 13 2nd Order Linear De
- 9 Differential Equation
- Thesis Guidelines
- Chapter 1
- Intro. to Mathematical Operation
- Business Plan Outline
- ece246 chapter1
- CONTENTGUIDELINE ETR300
- Ece246 Chapter 3
- No Devs Mesh
- ECE 246 Chapter 4
- Exp 4
- ese122_chpt1
- Methods circuit
- Experiment 3

)

CHAPTER 2: INPUT AND OUTPUT

Learning Outcomes

Able to apply the programming development procedure Able to understand the usage of printf with different data types of variables Able to understand the usage of scanf with different data types of variables

Lesson Outline Programming development procedure printf scanf .

3. 4. 2. Analyze the problem Develop a solution Code the solution Test and correct the program .Programming development procedure 1.

do: Extended analysis: obtain additional info about the problem so that you can thoroughly understand what is being asked and how to achieve the result . If necessary.Procedure 1: Analyze the problem Basic analysis: determine and understand the input items and the desired outputs items to be produced.

Procedure 2: Develop a solution Design & development: algorithm for transforming the input items into the desired outputs Top-down approach: start with the most general solution and refine it into clearly defined tasks .

Procedure 3: Code the solution Code the solution algorithm in C .

Procedure 4: Test & Debug the Program Select test data If error(s) found. make correction .

write a C program to calculate the resistance of a wire that is 125 feet long.Example The electrical resistance. and a is the crosssectional area of the wire (circular mills). r of a metal wire. in ohms is given by the formula: r = (ml)/a where m is the resistivity of the metal. . m is 10. Using this info. l is the length of the wire (feet). cross sectional area of 500 circular mills. and is copper.4. Resistivity of copper.

l and a .Step 1 Key problem statement: to calculate the resistance of the wire Output: resistance Inputs: m.

Step 2 Given formula: r = (ml)/a Pseudocodes: Assign values to m. l and a Calculate the resistance using the formula Display the result Do manual calculation to verify .

Step 3 #include <stdio. } .h> Int main() { float resistivity. area. length = 125. resistance = (resistivity * length)/ area. return 0. area = 500. resistance. resistance). printf(“The resistance of the wire (in ohms) is %f \n”. resistivity = 10.4. length.

Step 4 Verify the correctness of the program Try with different set of data and check with manual calculation .

33 ohm and 15 ohm resistors. . the total resistance is the sum of all 56 ohm. In such a circuit.Exercise Write a C program to calculate the total resistance of a series circuit.

. For integer: printf ("Integer = %d". . integer name). float name).").printf C function for output Used for printing/displaying text For string: printf (". For float printf ("Integer = %f"...some string.

&x). &i. . char ch.scanf C function for input Gets input from the keyboard Examples of scanf usage: int i. scanf ("%d %c %f". float x. &ch.

2. /* print sum */ return 0. /* prompt */ scanf( "%d". sum ). &integer2 ). /* variable in which sum will be stored */ printf( "Enter first integer\n" ).c Addition program */ #include <stdio.5: fig02_05. /* read an integer */ sum = integer1 + integer2. /* indicate that program ended successfully */ Definitions of variables scanf obtains a value from the user and assigns it to integer1 scanf obtains a value from the user and assigns it to integer2 Assigns a value to sum 23 24 } /* end function main */ Enter first integer 45 Enter second integer 72 Sum is 117 .h> /* function main begins program execution */ int main( void ) { int integer1.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 /* Fig. /* first number to be input by user */ int integer2. /* prompt */ scanf( "%d". /* assign total to sum */ printf( "Sum is %d\n". /* second number to be input by user */ int sum. /* read an integer */ printf( "Enter second integer\n" ). &integer1 ).

More Symbols… & . The value for the variable is then stored in the location % .is called conversion specifier. tells scanf or printf what types of data it is going to read. it tells scanf the location in memory at which the variable is located.is called ampersand (address operator in C) followed by a variable name. When combined a variable name. Printf and scanf treat this symbol as a special character that begins conversion specifier .

a type. a size and a value Whenever a new value is placed into a variable (through scanf. for example). it replaces (and destroys) the previous value Reading variables from memory does not change them .Memory Concepts Variable names correspond to locations in the computer's memory Every variable has a name.

Memory location showing the name and value of a variable. .

.Memory locations after both variables are input.

.Memory locations after a calculation.

More Operators… Standard algebraic equality operator or relational operator Equality operators Relational operators ≥ ≤ > < >= <= x > y x < y x >= y x <= y x is greater than y x is less than y x is greater than or equal to y x is less than or equal to y == != x == y x != y x is equal to y x is not equal to y C equality or relational operator Example of C condition Meaning of C condition .

Exercises: Fill in the blanks True/False Correct the error .

References Burgess. P.space. & Deitel. (1999).html SEE YOU NEXT LESSON! . M. C How To Program.J. C Programming Tutorial (K&R version 4) Deitel.unibe. (2007). H. Pearson International Edition http://www.M.ch/comp_doc/c_manu al/C/CONCEPT/data_types.

- CODEsign_2015Uploaded byMax Kleiner
- c Test Questions)Uploaded byRajeev Rupesh Ranjan
- countfunctionsUploaded byapi-252487731
- c Program to Reverse an ArrayUploaded byKarthik Gopalakrishnan
- Mcsl 17 c Lab ManualUploaded byAakash Goel
- Lesson 15 Array1Uploaded bySmita R. S.
- All in One Maths LabUploaded byAkshay Patra
- sr3Uploaded byAmit Kumar
- Mcsl 17 c Lab ManualUploaded byRashmi Sharma
- c ProgramsUploaded bySoubhagini Panda
- elab111Uploaded byKeerthivasan R
- C_C++Uploaded byKRISHNAVINOD
- APSC 160 (UBC)Uploaded byJFOXX7777
- Input OutputUploaded byHiten Saini
- 139928164-C-LanguageUploaded bylakhan2306
- Art_of_Programming_Contest_SE_for_uva.pdfUploaded byMatej Sladek
- Documentation on Analysis and DesignUploaded bySkakov Maksat
- 1292411593C Lect 1_IntroUploaded byAbel Ephraim
- 0aUploaded byAaron Hsu
- ds progUploaded byUtkarsh Sharma
- ArrayUploaded byMihaela Grubii
- Conditional Statements (Programming)Uploaded byLynJazminAbalus
- C Command Line ArgumentsUploaded byBarath
- Cmp220hwUploaded bysakhnini
- Match PointUploaded byM Rizqi Maulana R
- Compre Closed BookUploaded byGaurab Dasgupta
- ReadmeUploaded byAnonymous FTBYfqk
- IBM SAMPLE PAPER1[Www.placementPapers.net]Uploaded byskasc11bca122
- Introduction to C ProgrammingUploaded byAshish Kadam
- C-programming notesUploaded bySeshu Bollineni

- 10 Differential Equation (Update)Uploaded bylawlietll
- 5 Function of Two VariablesUploaded bylawlietll
- Application of 1st DerivativeUploaded bylawlietll
- Ece353 NotesUploaded bylawlietll
- 8 Extremum of FunctionUploaded bylawlietll
- 11 Applications of Separable EquationsUploaded bylawlietll
- Technical Paper (Latest) - FullllllUploaded bylawlietll
- 14 Applications of 2nd ODE [Read-Only]Uploaded bylawlietll
- 12 Applications of Linear EquationsUploaded bylawlietll
- 13 2nd Order Linear DeUploaded bylawlietll
- 9 Differential EquationUploaded bylawlietll
- Thesis GuidelinesUploaded bylawlietll
- Chapter 1Uploaded bylawlietll
- Intro. to Mathematical OperationUploaded bylawlietll
- Business Plan OutlineUploaded bylawlietll
- ece246 chapter1Uploaded bylawlietll
- CONTENTGUIDELINE ETR300Uploaded bylawlietll
- Ece246 Chapter 3Uploaded bylawlietll
- No Devs MeshUploaded bylawlietll
- ECE 246 Chapter 4Uploaded bylawlietll
- Exp 4Uploaded bylawlietll
- ese122_chpt1Uploaded bylawlietll
- Methods circuitUploaded bylawlietll
- Experiment 3Uploaded bylawlietll