BNF <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

Slides:



Advertisements
Similar presentations
#include void main() { float x = 1.66, y = 1.75; printf(%f%f,ceil(x), floor(y)); }
Advertisements

Chapter 11 Introduction to Programming in C
Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Introduction to C Systems Programming Concepts. Introduction to C A simple C Program A simple C Program –Variable Declarations –printf ( ) Compiling and.
Program Looping EE2372 Software Design I Dr. Gerardo Rosiles.
For(int i = 1; i
Recursion Prog #include <stdio.h> #include<conio.h> main()
1 A Simple C Program /* Take a number multiply it by 10 and display it */ #include main() { int number, result; printf("Type in a number \n"); scanf("%d",
Basic Logic – Chapter 3 IPC144 Week 3. Sequential Logic Statements executed sequentially – one after another Limited usefulness All programs shown so.
Fundamental of C programming
DS:Lab-1 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
ARDUINO CLUB Session 1: C & An Introduction to Linux.
ARDUINO CLUB What we’re really doing. BASICS The setup() and loop() functions.
 A string is an array of characters.  Strings must have a 0 or null character after the last character to show where the string ends.  The null character.
What is shape function ? shape function is a function that will give the displacements inside an element if its displacement at all the node locations.
Week 4 – Functions Introduction. Functions: Purpose Breaking a large problem into a series of smaller problems is a common problem- solving technique.
BNF. What is BNF? BNF stands for “Backus-Naur Form,” after the people who invented it BNF is a metalanguage--a language used to describe another language.
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
1 Chapter 10 Strings and Pointers. 2 Introduction  String Constant  Example: printf(“Hello”); “Hello” : a string constant oA string constant is a series.
Array_strcpy void array_strcpy(char dest[], char src[]) { int i = 0; while (src[i] != '\0') { dest[i] = src[i]; i++; } dest[i] = '\0'; }
Sort the given string, without using string handling functions.
Solution April 13, #include int main( void ) { int salaries[ 11 ] = { 0 }; /*total salary */ int sales; /* sales per karyawan */ double salary;
1 Selection in C. 2 If / else if statement:  The else part of an if statement can be another if statement. if (condition) … else if (condition) … else.
Review for midterm exam Dilshad M. Shahid Spring NYU.
Introduction to Computers and Programming Class 6 Introduction to C Professor Avi Rosenfeld.
1 Introduction to Computers and Programming Class 3 Introduction to C Professor Avi Rosenfeld.
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
C programming an Introduction. Types There are only a few basic data types in C. char a character int an integer, in the range -32,767 to 32,767 long.
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
Agenda  Commenting  Inputting Data from Keyboard (scanf)  Arithmetic Operators  ( ) * / + - %  Order of Operations  Mixing Different Numeric Data.
Word Problems that Lead to Inequalities. Word Problem Solving Strategies Read through the entire problem. Highlight the important information and key.
A Program is nothing but the execution of sequence of one or more Instructions. On the basis of application it is essential. To Alter the flow of a program.
C STRUCTURES. A FIRST C PROGRAM  #include  void main ( void )  { float height, width, area, wood_length ;  scanf ( "%f", &height ) ;  scanf ( "%f",
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Decision making statements. Decision making statements are used to skip or to execute a group of statements based on the result of some condition. The.
COP 3275 COMPUTER PROGRAMMING USING C Instructor: Diego Rivera-Gutierrez
Chapter 5 – Functions II Outline Recursion Examples Using Recursion: The Fibonacci Series.
Department of Electronic & Electrical Engineering IO reading and writing variables scanf printf format strings "%d %c %f"
LOOPING IN C. What would be the output of the following program main( ) { int j ; while ( j
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Arrays Outline 6.1Introduction 6.2Arrays 6.3Declaring.
1 CSC103: Introduction to Computer and Programming Lecture No 9.
Word problems that lead to inequalities. Word Problem Solving Strategies Read through the entire problem. Highlight the important information and key.
ARRAYS.
Lesson #4 Logical Operators and Selection Statements.
Lesson #4 Logical Operators and Selection Statements.
Decision making If.. else statement.
ECE Application Programming
ECE Application Programming
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
COMPARISON OF MEANS QUESTION #10c
ECE Application Programming
- Standard C Statements
Compound Condition Break , Continue Switch Statements in Java
ECE Application Programming
Chapter 3: I/O Management
By: Syed Shahrukh Haider
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Chapter 9 - Arrays Outline 6.1 Introduction 6.2 Arrays
Decision making If statement.
The Big 6 Research Model Step 3: Location and Access
Hmjngj jxhngh.
SELECTIONS STATEMENTS
Lesson 12: more on Equations
EECE.2160 ECE Application Programming
Character Arrays char string1[] = “first”;
Dale Roberts, Lecturer IUPUI
Arrays, Part 1 of 2 Topics Definition of a Data Structure
EECE.2160 ECE Application Programming
Range check 範圍檢查: int age; int score; int month; 1-12
Presentation transcript:

BNF <digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 <unsigned_int_const> ::= <digit> [ <digit> ] ... <signed_int_const> ::= [ + | - ] <unsigned_int_const> <float_const> ::= <signed_int_const> [ . [ <unsigned_int_const>] ] f <double_const> ::= <signed_int_const> [ . [ <unsigned_int_const>] ] <up_alpha> ::= A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z <low_alpha> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z <alpha> ::= <up_alpha> | <low_alpha> <alphanum> ::= <alpha> | <digit> <alphanumext> ::= <alpha> | <digit> | _ <variable> ::= _ | <alpha> [ <alphanumext> ]...

BNF (details) f is required (no brackets) [ ] mean optional OR <float_const> ::= <signed_int_const> [ . [ <unsigned_int_const>] ] f OR zero or more <variable> ::= _ | <alpha> [ <alphanumext> ]... a variable must begin with a _ or alpha character, and may be followed by 0 or more alphanumext characters

BNF <expression> ::= <term> <assignment_stmnt> ::= <variable> = <expression> ; <simple_stmnt> ::= <assignment statement> | <system_function_call> | <user_function_call> | <while_stmnt> | <if_stmnt> | <for_stmnt> // many more <compound_stmnt>::= { [ <simple_stmnt> ]... } <statement> ::= <simple_stmnt> ; | <compound_stmnt>

BNF (if) <if_stmnt> ::= if ( <expression> ) <statement> [ else <statement> ]

if if (a > b) big = a; else big = b; if (a+6*3-43) printf("wow is this not cool"); else printf("this is not cool");

if (relational operators) > Greater than >= Greater than or equal to < Less than <= Less than or equal to == Equal != Not Equal

if (Logical operators) (As covered before in expression evaluation) Recall expressions with Logical Operators evaluate to either zero or Non-zero && Logical AND || Logical OR ! Logical NOT

if (common pitfalls) a single equals means ASSIGN. x=12345; a double equal must be used to check for equality. x=12345; if (x=3) { printf("x is 3\n"); } else { printf("x is not 3\n"); } This code will ALWAYS print: x is 3

if (uses for a single = in ifs) if ( (disc = b*b-4*a*c) < 0 ) { // something } else { // another something }

if (range checking - take 1) int n; printf("Enter a number 1 to 10: "); scanf("%d",&n); if (n > 10) { printf("Idiot!"); } else { if (n < 1) { printf("Idiot!"); } else { printf("Good job!"); } }

if (range checking - take 2) If there is only one statement needed for the true and/or false condition, the {} are not needed int n; printf("Enter a number 1 to 10: "); scanf("%d",&n); if (n > 10) printf("Idiot!"); else if (n < 1) printf("Idiot!"); else printf("Good job!");

if (range checking - take 3) Use the && or || as needed to check for multiple conditions int n; printf("Enter a number 1 to 10: "); scanf("%d",&n); Note these ( ) are needed if ( (n > 10) || (n < 1) ) printf("Idiot!"); else printf("Good job!");

if (range checking - take 4) Use the && or || as needed to check for multiple conditions int n; printf("Enter a number 1 to 10: "); scanf("%d",&n); Note these ( ) are needed if ( (1 <= n) && (n <= 10) ) printf("Good job!"); else printf("Idiot!");

if (range checking) (The WRONG WAY) int n; printf("Enter a number 1 to 10: "); scanf("%d",&n); if (1 <= n <= 10 ) // THIS WILL NOT COMPILE printf("Good job!"); else printf("Idiot!");

if (example) void main(void) { float a,b,c,disc; : scanf("%f %f %f",&a,&b,&c); if (a==0) { // statements } else { disc = b*b-4*a*c; if ( disc < 0 ) { // statements } else { // statements } } }

ECE 160 03/04/2005 if (alternative form) if (a > b) big = a; else big = b; The above code may be replaced by: big = (a>b)?a:b General form: [ variable = ] expression1 ? expression2 : expression3 if expression1 is non-zero, expression2 is evaluated and optionally assigned; if expression1 is zero, expression3 is evaluated and optionally assiged; (c) 2005, P. H. Viall