Control Statements in C

Slides:



Advertisements
Similar presentations
Lecture Computer Science I - Martin Hardwick The Programming Process rUse an editor to create a program file (source file). l contains the text of.
Advertisements

Variables in C Amir Haider Lecturer.
C++ Basics Variables, Identifiers, Assignments, Input/Output.
Chapter 3: Beginning Problem Solving Concepts for the Computer Programming Computer Programming Skills /1436 Department of Computer Science.
Structure of a C program
C Programming Basics Lecture 5 Engineering H192 Winter 2005 Lecture 05
C Language Brief history In 1972, Dennis Ritchie designed C and it was used on PDP-11 mini- computers In 1974, Unix was rewritten in C C++ and C Advantages.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Control Statements in C. C Keywords autodoubleintstruct breakelselongswitch caseenumregistertypedef charexternreturnunion constfloatshortunsigned continueforsignedvoid.
Lecture No: 16. The scanf() function In C programming language, the scanf() function is used to read information from standard input device (keyboard).
CS 192 Lecture 3 Winter 2003 December 5, 2003 Dr. Shafay Shamail.
COMPUTER PROGRAMMING. Data Types “Hello world” program Does it do a useful work? Writing several lines of code. Compiling the program. Executing the program.
C Tokens Identifiers Keywords Constants Operators Special symbols.
C-Language Keywords(C99)
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
COMPUTER PROGRAMMING. variable What is variable? a portion of memory to store a determined value. Each variable needs an identifier that distinguishes.
1.Identifiers 2.Variables 3.Keywords 4.Statements 5.Comments 6.Whitespaces 7.Syntax 8.Semantic © In this session we will.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Variables and Data Types.  Variable: Portion of memory for storing a determined value.  Could be numerical, could be character or sequence of characters.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 5P. 1Winter Quarter C Programming Basics Lecture 5.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Types of C Variables:  The following are some types of C variables on the basis of constants values it has. For example: ○ An integer variable can hold.
Gator Engineering 1 Chapter 2 C Fundamentals (Continued) Copyright © 2008 W. W. Norton & Company. All rights reserved.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
CMSC 1041 Variables in C Declaring, Naming, Using Variables.
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
Variables in C Topics  Naming Variables  Declaring Variables  Using Variables  The Assignment Statement Reading  Sections
CMSC 104, Version 8/061L09VariablesInC.ppt Variables in C Topics Naming Variables Declaring Variables Using Variables The Assignment Statement Reading.
2. C FUNDAMENTALS. Example: Printing a Message /* Illustrates comments, strings, and the printf function */ #include int main(void) { printf("To C, or.
C syntax (simplified) BNF. Program ::= [ ] Directives ::= [ ] ::= | |… ::=#include > ::=#define.
C++ Lesson 1.
Asst.Prof.Dr. Tayfun ÖZGÜR
Data types Data types Basic types
LESSON 3 IO, Variables and Operators
C Short Overview Lembit Jürimägi.
Introduction to C Programming Language
مبانی کامپیوتر و برنامه سازی
CMSC 104, Section 4 Richard Chang
Introduction to C Programming
CSE101-Lec#3 Components of C Identifiers and Keywords Data types.
Reserved Words.
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
CMSC 104, Section 4 Richard Chang
null, true, and false are also reserved.
Character Set The character set of C represents alphabet, digit or any symbol used to represent information. Types Character Set Uppercase Alphabets A,
פרטים נוספים בסילבוס של הקורס
درس برنامه‌سازي کامپيوتر
Variables in C Topics Naming Variables Declaring Variables
Basics of ‘C’.
פרטים נוספים בסילבוס של הקורס
Introduction to C Programming
Govt. Polytechnic,Dhangar
Variables in C Topics Naming Variables Declaring Variables
UMBC CMSC 104 – Section 01, Fall 2016
Introduction C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell.
Control structures Chapter 3.
Govt. Polytechnic,Dhangar
Variables in C Declaring , Naming, and Using Variables.
Control structures Chapter 3.
2. Second Step for Learning C++ Programming • Data Type • Char • Float
Programming Language C Language.
Control structures Chapter 3.
Building Blocks of C Programming Language
Variables in C Topics Naming Variables Declaring Variables
2008/10/01: Lecture 8 CMSC 104, Section 0101 John Y. Park
C Language B. DHIVYA 17PCA140 II MCA.
Variables in C Topics Naming Variables Declaring Variables
Variables in C Topics Naming Variables Declaring Variables
INTRODUCTION TO C.
Variables in C Topics Naming Variables Declaring Variables
Presentation transcript:

Control Statements in C

C Keywords auto double int struct break else long switch case enum register typedef char extern return union const float short unsigned continue for signed void default goto sizeof volatile do if static while The words in bold print are used in control statements. They change the otherwise sequential execution of the assignment statements in a function block

assignment statement aResult = 10; aResult = countB; aResult = (aValue + 100) / countD; aResult = sqrt (aValue);

block of statements { const int MAX_BINS = 11; int orderNumber; int binNumber; printf("Enter order number: "); scanf("%d", &orderNumber); binNumber = orderNumber % MAX_BINS; printf("Bin number is %d\n", binNumber); }

simple “if” statement if (aNumber != 1000) countA++;

“if” with a block of statements if (aValue <= 10) { printf("Answer is %8.2f\n", aValue); countB++; } // End if

“if” – “else” with a block of statements if (aValue <= 10) { printf("Answer is %8.2f\n", aValue); countB++; } // End if else { printf("Error occurred\n"); countC++; } // End else

nested “if” statement if (aValue == 1) countA++; else if (aValue == 10) countB++; else if (aValue == 100) countC++; else countD++;

“while” with a single statement while (aResult >= 1000) aResult = aResult / aValue;

“while” with a block of statements while (aResult >= 1000) { aResult = aResult / aValue; printf("Result is %9.4f\n", aResult); } // End while

“while” with nested “if” statements aResult = MAX_VALUE; while (aResult >= 1000) { countW++; // nested if statement if (aValue == 1) countA++; else if (aValue == 10) countB++; else if (aValue == 100) countC++; else countD++; aResult = aResult / aValue; } // End while

“while” performing an infinite loop while (1) { receiveFrom (aClient, aRequest); theResults = processRequest(aRequest); sendTo (aClient, theResults); } // End while

“for” with a single statement for (i = 1; i <= MAX_LENGTH; i++) printf("#");

“for” with a block of statements for (i = 0; i < MAX_SIZE; i++) { printf("Symbol is %c\n", aBuffer[i]); aResult = aResult / i; } // End for

“for” performing an infinite loop for (;;) { receiveFrom (client, request); results = processRequest(request); sendTo (client, Results); } // End for

“switch” statement switch (aNumber) { case 1 : countA++; break; case 10 : countB++; break; case 100 : case 500 : countC++; break; default : countD++; } // End switch 