Download presentation
Presentation is loading. Please wait.
Published byEugene Alexander Modified over 9 years ago
1
1 Types of Programming Language (1) Three types of programming languages 1.Machine languages Strings of numbers giving machine specific instructions Example: +1300042774 +1400593419 +1200274027 2.Assembly languages English-like abbreviations representing elementary computer operations (translated via assemblers) Example: LOAD BASEPAY ADD OVERPAY STORE GROSSPAY
2
2 Types of Programming Language (2) 3.High-level languages Codes similar to everyday English Use mathematical notations (translated via compilers) Example: grossPay = basePay + overTimePay
3
3 High Level Languages FORTRAN Used for scientific and engineering applications COBOL Used to manipulate large amounts of data; still used in established business- software Pascal Designed for the teaching of structured programming C Evolved by Ritchie from two previous programming languages, BCPL and B (early 1970s) Used to develop UNIX and other modern operating systems Standardized in 1989 and 1999 into an "unambiguous, machine- independent" definition Hardware independent (portable)
4
4 The C Program Environment 1.Edit 2.Preprocess 3.Compile 4.Link 5.Load 6.Execute Editor program is used to write C source code Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler creates object code and stores it on disk. Linker links the object code with the libraries Loader Primary Memory Compiler Editor Preprocessor Linker Primary Memory........................ Dis k CPU Dis k Preprocessor program processes the code.
5
5 A First C Program (1) Comments Text surrounded by /* and */ is ignored by computer Used to describe program #include Preprocessor directive Tells computer to load contents of a certain file allows standard input/output operations 1 /* Fig. 2.1: fig02_01.c 2 A first program in C */ 3 #include 4 5 /* function main begins program execution */ 6 int main() 7 { 8 printf( "Welcome to C!\n" ); 9 10 return 0; /* indicate that program ended successfully */ 11 12 } /* end function main */
6
6 A First C Program (2) int main() The keyword main indicates where the program starts executing Parenthesis ( ) always follow the word main int means that main "returns" an integer value (more on this later!) Braces ( { and } ) indicate a block of code The body of main must be contained in braces
7
7 A First C Program (3) printf( "Welcome to C!\n" ); Instructs computer to perform an action Specifically, prints the string of characters within quotes ( " " ) Entire line called a statement All statements must end with a semicolon ( ; ) Escape character ( \ ) Indicates that printf should do something out of the ordinary \n is the newline character return 0; Indicates the end of the main function
8
8 Compiling and Executing… (5)
9
9 An Alternative First C Program Produces the same output as the previous program Another variation printf(“Welcome\nto\nC!\n”); would produce three lines of output, with newlines inserted after the words welcome and to, as well as at the end.
10
10 Adding two Numbers (Program Listing)
11
11 Adding two Numbers (New Concepts) Lines 13 and 16 read input from the keyboard: scanf( "%d", &integer1 ); scanf( "%d", &integer2 ); Lines 8 - 10 declare the program’s variables: int integer1; int integer2; int sum; Line 18 performs a mathematical calculation on the numbers input from the keyboard: sum = integer1 + integer2; Line 20 prints to the screen the result of this calculation: printf( "Sum is %d\n", sum )
12
12 Adding two Numbers (Discussion) As before Comments, #include and main int integer1, integer2, sum; Definition of variables Variables: locations in memory where a value can be stored int means the variables can hold integers (e.g. - 1, 3, 0, 47 )
13
13 Adding two Numbers (Discussion) Variable names (identifiers) integer1, integer2, sum Identifiers: consist of letters, digits (cannot begin with a digit) and underscores( _ ) Case sensitive Definitions appear before executable statements If an executable statement references and undeclared variable it will produce a syntax (compiler) error
14
14 Adding two Numbers (Discussion) scanf( "%d", &integer1 ); Obtains a value from the user scanf uses standard input (usually keyboard) This scanf statement has two arguments %d - indicates data should be a decimal integer & is confusing in beginning – for now, just remember to include it with the variable name in scanf statements When executing the program the user responds to the scanf statement by typing in a number, then pressing the enter (return) key
15
15 Adding two Numbers (Discussion) = (assignment operator) Assigns a value to a variable Is a binary operator (has two operands) sum = integer1 + integer2; sum gets the result of integer1 + integer2; Variable receiving value on left printf( "Sum is %d\n", sum ); Similar to scanf %d means decimal integer will be printed sum specifies what integer will be printed Calculations can be performed inside printf statements printf( "Sum is %d\n", integer1 + integer2 ); Write down some sample screen output that you would expect to see when the program is run
16
16 Adding two Numbers (Output) This shows an example of what you see when you run this program: Enter first integer 45 Enter second integer 72 Sum is 117
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.