Download - BDA 24202 COMPUTER PROGRAMMING
![Page 1: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/1.jpg)
BDA 24202COMPUTER PROGRAMMING
Ts. Dr. Norfazillah Talib
JKP, FKMP
![Page 2: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/2.jpg)
C language
- Structure programming language
- Programmer able to focus on problem rather than machine that program will be execute
- Able to run at various hardware platform
![Page 3: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/3.jpg)
Structure C programming
Preprocessor directive (processing directive)
Global declaration
Local declaration
Main function
![Page 4: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/4.jpg)
Greeting program
• Task: Display “Hello world!”
![Page 5: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/5.jpg)
Comments
• Character that are not executed as part of the program.
• Use for mark or debug the code
• Syntax:
/* …. Comments…..
Comment………….*/ block comments
//…. Comment line comments (for 1 line only)
![Page 6: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/6.jpg)
Preprocessor directive
• Not the part of the compiler but it is directive to preprocessor
![Page 7: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/7.jpg)
Variables
Variables are named memory locations that have a type,such as integer or character, which is inherited from theirtype. The type determines the values that a variable maycontain and the operations that may be used with itsvalues.
Variable Declaration
Variable Initialization
Topics discussed in this section:
![Page 8: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/8.jpg)
![Page 9: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/9.jpg)
• int new;
• float maxItems; //word separator: capital
• double max_items; // word separator: underscor
• int new, old, great; //combination of same type variable
• Int loadA=30, loadB=15; //initialize the variable
Examples of Variable Declarations and Definitions
![Page 10: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/10.jpg)
10
When a variable is defined, it is not initialized.
We must initialize any variable requiring
prescribed data when the function starts.
Note
![Page 11: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/11.jpg)
Identifiers
One feature present in all computer languages is theidentifier. Identifiers allow us to name data and otherobjects in the program. Each identified object in thecomputer is stored at a unique address.
![Page 12: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/12.jpg)
Rules for Identifiers1. First character must be alphabetic character or underscore
2. Must consist only of alphabetic characters, digits or underscores
3. Commas or blank spaces are not allowed within an identifier.
4. First 63 characters of an identifier are significant
5. Cannot duplicate a keyword (reserved word).
6. Identifiers are also case sensitive in C (e.g name and Name are two different identifiers in C).
7. No special characters, such as semicolon, period, whitespaces, slash or comma are permitted to be used in or as Identifier
![Page 13: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/13.jpg)
Reserved word
![Page 14: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/14.jpg)
ExerciseDetermine whether the following identifiers is valid or invalid. Give reason for invalid cases.1) int Parit Raja 2) int 20thCentury 3) int char4) long float INTEGER5) int _BMW2003 6) int Reservedword7) float BDA24202 8) long int markah_pelajar 9) char jam*kredit 10) double printf
![Page 15: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/15.jpg)
Computer Science: A Structured Programming Approach Using C
15
Constant/ Escape Character
![Page 16: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/16.jpg)
Computer Science: A Structured Programming Approach Using C
16
Table 2-10 Format Codes for Output
![Page 17: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/17.jpg)
Computer Science: A Structured Programming Approach Using C
17
Streams
Formatting Input/Output
Topics discussed in this section:
![Page 18: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/18.jpg)
Computer Science: A Structured Programming Approach Using C
18
FIGURE 2-15 Stream Physical Devices
![Page 19: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/19.jpg)
Computer Science: A Structured Programming Approach Using C
19
FIGURE 2-18 Conversion Specification
![Page 20: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/20.jpg)
Computer Science: A Structured Programming Approach Using C
20
Table 2-11 Flag Formatting Options
![Page 21: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/21.jpg)
Computer Science: A Structured Programming Approach Using C
21
FIGURE 2-17 Output Stream Formatting Example
![Page 22: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/22.jpg)
Computer Science: A Structured Programming Approach Using C
22
FIGURE 2-20 Input Stream Formatting Example
scanf
![Page 23: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/23.jpg)
Computer Science: A Structured Programming Approach Using C
23
scanf requires variable addresses in the address list.
Note
![Page 24: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/24.jpg)
Computer Science: A Structured Programming Approach Using C
24
PROGRAM Write A Program That Prints “Nothing!”
#include<conio.h>
getchar();
\a\a\a
![Page 25: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/25.jpg)
Output
![Page 26: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/26.jpg)
Computer Science: A Structured Programming Approach Using C
26
PROGRAM Print Sum of Three Numbers
![Page 27: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/27.jpg)
Computer Science: A Structured Programming Approach Using C
27
PROGRAM Print Sum of Three Numbers (continued)
![Page 28: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/28.jpg)
Computer Science: A Structured Programming Approach Using C
28
PROGRAM Print Sum of Three Numbers (continued)
![Page 29: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/29.jpg)
Write a program to add two numbers
EXERCISE
![Page 30: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/30.jpg)
Computer Science: A Structured Programming Approach Using C
30
Constants
Constants are data values that cannot be changed duringthe execution of a program. Like variables, constantshave a type. In this section, we discuss Boolean,character, integer, real, complex, and string constants.
Constant Representation
Coding Constants
Topics discussed in this section:
![Page 31: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/31.jpg)
Computer Science: A Structured Programming Approach Using C
31
Memory ConstantsPROGRAM
![Page 32: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/32.jpg)
Computer Science: A Structured Programming Approach Using C
32
PROGRAM Memory Constants (continued)
![Page 33: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/33.jpg)
ASCII Table
(American Standard
Code for Information
Interchange)
![Page 34: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/34.jpg)
Computer Science: A Structured Programming Approach Using C
34
PROGRAM Print Value of Selected Characters
![Page 35: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/35.jpg)
Computer Science: A Structured Programming Approach Using C
35
PROGRAM Print Value of Selected Characters (continued)
![Page 36: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/36.jpg)
Computer Science: A Structured Programming Approach Using C
36
PROGRAM Print Value of Selected Characters (continued)
![Page 37: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/37.jpg)
Computer Science: A Structured Programming Approach Using C
37
PROGRAM Print Value of Selected Characters (continued)
![Page 38: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/38.jpg)
OUTPUT#include <stdio.h>int main(){char A =‘A’;char a =‘a’;char zed =‘z’;char eight =‘8’;char dblQuote =‘”’;printf (“ASCII for char ‘A’ is: %d\n”, A);printf (“ASCII for char ‘a’ is: %d\n”, a);printf (“ASCII for char ‘z’ is: %d\n”, zed);printf (“ASCII for char ‘8’ is: %d\n”, eight);printf (“ASCII for char ‘\”’ is: %d\n”, dblQuote);return 0;}
EXAMPLE
![Page 39: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/39.jpg)
![Page 40: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/40.jpg)
Computer Science: A Structured Programming Approach Using C
40
OUTPUT
Write a program that can calculate the circumference and area
of circle once radius of the circle is filled.
![Page 41: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/41.jpg)
Computer Science: A Structured Programming Approach Using C
41
PROGRAM Calculate a Circle’s Area and Circumference
![Page 42: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/42.jpg)
Computer Science: A Structured Programming Approach Using C
42
PROGRAM Calculate a Circle’s Area and Circumference
![Page 43: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/43.jpg)
Computer Science: A Structured Programming Approach Using C
43
PROGRAM A Sample Inventory Report
![Page 44: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/44.jpg)
Computer Science: A Structured Programming Approach Using C
44
PROGRAM A Sample Inventory Report (continued)
![Page 45: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/45.jpg)
Computer Science: A Structured Programming Approach Using C
45
FIGURE 2-22 Output Specifications for Inventory Report
![Page 46: BDA 24202 COMPUTER PROGRAMMING](https://reader030.vdocuments.mx/reader030/viewer/2022012101/61db960222410342d627a049/html5/thumbnails/46.jpg)
Price: RM _______
Quantity: ______
Total price: RM_________
Thanks for shopping here!
Output
Develop a program that can calculate the total price of goods
once the price and quantity of goods are filled.