1 / 11

Program Development Cycle

Program Development Cycle. Edit program Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied, go back to #1. My First C Program. /* Arup Guha My First C Program 8/23/07 COP 3223 Rocks! */ #include <stdio.h>

brandi
Download Presentation

Program Development Cycle

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Program Development Cycle Edit program Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied, go back to #1.

  2. My First C Program /* Arup Guha My First C Program 8/23/07 COP 3223 Rocks! */ #include <stdio.h> int main(void) { printf(“COP 3223 Rocks!\n”); return 0; }

  3. Purpose of Comments • To tell the reader basic information about the program • Who wrote it • When they wrote it • What it does • Any other useful information about it • Inside code, they inform the reader about the specific function of a group of statements.

  4. #includes • Tells the compiler that you may be using prewritten C functions for a particular library. • We will always use stdio.h – it allows us to do standard input and output. • When you call a function for a C library, it will look to all of the libraries you have included to find out HOW to run the function.

  5. Function main • The only code directly executed is the code inside of main • The beginning and ending are delineated by { and }, respectively. • Everything else is run in sequential order, as it is listed. • Other functions (like printf) ONLY run if they are called from main, OR from another function called by main, etc.

  6. printf • Prewritten C function in stdio.h • Prints out everything inside of “” exactly with these exceptions • A backslash and the character after it • A percent sign and the character after it • Prints go in order, and the cursor starts where the last print ended.

  7. Exceptions for prints • Backslash – Escape Sequence • \n is a newline • \t is a tab • \\ is a backslash • \” is a double quote • Percent Codes (Will be explained later) • %d (for integer variable) • %lf (for double variable) • %c (for character)

  8. Variables • Types we will commonly use • int • char • double • How to Declare a Variable • <type> <name>; • Examples • int value; • char my_letter, your_letter; • double money;

  9. Assignment Statement ( = ) • ONE EQUAL SIGN, NOT TWO • Syntax: <variable> = <expression> • What it does: • Calculates the value of <expression> at that point in time. • Changes the value of <variable> to this NEW value.

  10. /* Arup Guha My Second C Program 8/23/07 Computes the number of feet in a mile */ #include <stdio.h> int main(void) { // Declare variables int feet_in_mile, yards_in_mile; int feet_in_yard; // Make calculation yards_in_mile = 1760; feet_in_yard = 3; feet_in_mile = yards_in_mile*feet_in_yard; // Output the result printf(“Mile = %d Feet.\n”, feet_in_mile); return 0; }

  11. % code explanation • If %d or a similar percent code is encountered inside “” of a printf, this is what happens • An expression must be specified after the end of the double quote, separated by a comma • Value of this expression is printed in the FORMAT of the type specified by the percent code. • Experiment to see what happens if you use the wrong percent code.

More Related