Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,"— Presentation transcript:

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

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

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 – ; Examples –int value; –char my_letter, your_letter; –double money;

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

10 /* Arup Guha My Second C Program 8/23/07 Computes the number of feet in a mile */ #include 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.


Download ppt "Program Development Cycle 1.Edit program 2.Compile program - translates it from C to machine language 3. Run/execute your program. 4. If not satisfied,"

Similar presentations


Ads by Google