3 - ICS103 Programming in C Lecture 3: Introduction to C...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
1 ICS103 Programming in C Lecture 3: Introduction to C (2)
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Outline Overview of C Why C? What’s Missing? General form of a C program C Language Elements Preprocessor Directives Comments The “main” function Variable Declarations and Data Types Executable Statements Reserved Words Identifiers Formatting Numbers in Program Output
Background image of page 2
3 Executable Statements /* Converts distances from miles to kilometers */ #include <stdio.h> /* printf, scanf definitions */ #define KMS_PER_MILE 1.609 /* conversion constant */ int main(void) { double miles, //distance in miles kms; //equivalent distance in kilometers //Get the distance in miles printf("Enter the distance in miles> "); scanf("%lf", &miles); //Convert the distance to kilometers kms = KMS_PER_MILE * miles; //Display the distance in kilometers printf("That equals %f kilometers.\n", kms); return (0); }
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Executable Statements Executable Statements: C statements used to write or code the algorithm. C compiler translates the executable statements to machine code. Input/Output Operations and Functions printf Function scanf Function Assignment Statements return Statement
Background image of page 4
5 Input/Output Operations and Functions Input operation - data transfer from the outside world into computer memory Output operation - program results can be displayed to the program user Input/output functions - special program units that do all input/output operations printf = output function scanf = input function Function call - in C a function call is used to call or activate a function Calling a function means asking another piece of code to do some work for you
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 The printf Function function name printf(“That equals %f kilometers.\n”, kms); function arguments format string print list place holder 
Background image of page 6
7 Placeholders Placeholder always begins with the symbol % It marks the place in a format string where a value will be printed out or will be inputed (in this case, kms) Format strings can have multiple placeholders, if you are printing multiple values Placeholder Variable Type Function Use %c char printf/scanf %d int printf/scanf %f double printf %lf double scanf newline escape sequence – ‘\n’ terminates the current line
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 25

3 - ICS103 Programming in C Lecture 3: Introduction to C...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online