Topics covered Structure of C Program, Life Cycle of Program from Source code to Executable, Compiling and Executing C Code, Keywords, Identifiers, Primitive.

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

11-2 Identify the parts of the “main” function, which include Preprocessor Directives main function header main function body which includes Declaration.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
Topic R3 – Review for the Final Exam. CISC 105 – Review for the Final Exam Exam Date & Time and Exam Format The final exam is 120-minutes, closed- book,
Agenda Review User input Scanner Strong type checking Other flow-control structures switch break & continue Strings Arrays 2.
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
C Tokens Identifiers Keywords Constants Operators Special symbols.
1 CSC103: Introduction to Computer and Programming Lecture No 11.
Computers and Programming CPC The 2 nd lecture Jiří Šebesta.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
1 Do-While Statement Is a looping control structure in which the loop condition is tested after each iteration of the loop. SYNTAX do { Statement } while.
CompSci 100E 2.1 Java Basics - Expressions  Literals  A literal is a constant value also called a self-defining term  Possibilities: o Object: null,
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
C Programming Lecture 7 : Control Structures. Control Structures Conditional statement : if, switch Determine a block of statements to execute depending.
Lecture 13 Transition from Fortran to C Yi Lin Feb 27, 2007.
Introduction to Programming
Decision Making It is used to change the order of the program based on condition. Categories: – Sequential structure – Selection structure – Iteration.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
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.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
CMSC 1041 More Loops ‘for’ loops and ‘do-while’ loops.
Session 2 Operators, Decisions and Loops. Objectives Operators Casting data Decision marking structures Loops break, continue, return.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
CS1010 Discussion Group 11 Week 5 – Functions, Selection, Repetition.
Numbers in ‘C’ Two general categories: Integers Floats
Unit 3 Control Structure
ECE Application Programming
Programming in Java Sachin Malhotra, Chairperson, PGDM-IT, IMS Ghaziabad Saurabh Chaudhary, Dean, Academics, IMS Ghaziabad.
2. Java language basics (2)
Sachin Malhotra Saurabh Choudhary
Decisions Chapter 4.
C++ Programming: CS150 For.
C Program Controls + Flow Structure
C++, OBJECT ORIENTED PROGRAMMING
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
C Short Overview Lembit Jürimägi.
For loops Increment ,decrement operations
CSCI206 - Computer Organization & Programming
Chapter 4: Making Decisions.
Lecture 2-3 C++ Basic Constructs
Formatted and Unformatted Input/Output Functions
Advanced Programming Behnam Hatami Fall 2017.
The C “switch” Statement
INC 161 , CPE 100 Computer Programming
Introduction to Programming
Looping.
The C “switch” Statement
Explicit and Implicit Type Changes
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
פרטים נוספים בסילבוס של הקורס
Java - Data Types, Variables, and Arrays
Chapter 5 Decision Making and Branching
פרטים נוספים בסילבוס של הקורס
Java Tokens & Data types
The switch Statement Topics Multiple Selection switch Statement
Variables & Data types Selection Statements Additional Operators
Structured Program Development in C
Conversion Check your class notes and given examples at class.
WEEK-2.
Control Structures Lecture 6.
Winter 2019 CMPE212 4/7/2019 CMPE212 – Reminders
Fundamental Programming
Welcome back to Software Development!
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
Structured Program Development in C
INTRODUCTION TO C.
Getting Started With Coding
Chapter 13 Control Structures
Visit for more Learning Resources
Presentation transcript:

Topics covered Structure of C Program, Life Cycle of Program from Source code to Executable, Compiling and Executing C Code, Keywords, Identifiers, Primitive Data types in C, variables, constants, input/output statements in C, operators, type conversion and type casting. Conditional branching statements, iterative statements, nested loops, break and continue statements.

Keywords or reserved words You cannot use them for variable names

Identifiers – variable names They must start with an alphabet May contain digits or alphabets. int abc123, abc_123, abc; //valid identifiers

Datatypes in C

Primitive Data types in C

Variables and constants

I/O statements in C Input: scanf(), gets() Output: printf(), puts() main(){ char s[20]; //string is array of char puts("Enter a string: "); gets(s); puts("Here is your string"); puts(s); }

Operators in C Uniary (1 var) x = x+1; or x++; Binary (2 var) a = b*c; Ternary operator (3 var) ?: main(){ int a=1,b=2,c; c = a>b?a:b; //condition?option1:option2 printf("c = %d\n",c); } //output is 2

Operators – 3 types

Integer and double are default main(){ printf("%d\n",sizeof('x')); //int printf("%d\n",sizeof(55)); //int printf("%d\n",sizeof(55.0)); //double } //Output will be 4 4 8 because ‘x’ will become integer for its ASCII value

Type conversion - implicit #include<stdio.h> main(){ //implicit typecasting to float float f = 10.0; printf("\n f = %f",f); printf("\nsize of 10.0 = %d",sizeof(10.0)); printf("\nsize of f = %d",sizeof(f)); } //output: f = 10.0000 size of 10.0 = 8 size of f = 4

Type conversion - explicit main(){ //explicit typecasting to float float f = (float)10.0; printf("\n value of = %f",f); }

Conditional branching statements

If statement main(){ int a=10; if(a<20) { printf("a<20\n"); } if(a>20) { printf("a>20\n"); }} //output is a<20

If-else main(){ int a=10; if(a<20) { printf("a<20\n"); } else { printf("a>20\n"); }} //output is a<20

Switch statement main(){ int a=10; switch(a) { case 20: printf("a=20\n"); break; case 10: printf("a=10\n"); break; default: printf("unknown"); }} //output is a=10

Iterative statements - repetitions

for loop

Factorial using while main(){ int i=1,n=5,f=1; while(i<=n){ f = f*i; i++; } printf("%d",f);

Factorial using while main(){ int i=1,n=5,f=1; do{ f = f*i; i++; } while(i<=n); printf("%d",f); }

Factorial using for main(){ int i,n=5,f=1; for(i=1;i<=n;i++){ f = f*i; } printf("%d",f);

Nested loops – loop within loop

What is the output? main(){ int i,j,n=6; for(i=1;i<=n;i++){ for(j=1;j<=i;j++){ printf("*"); } printf("\n"); }}

break and continue Break statement helps to break from the immediate local loop for certain condition. main(){ int i,j; for(i=1;i<=10;i++){ if(i%6==0) break; //if the number is div by 6 } printf("i=%d",i); //output i=6

Continue – skip to next iteration main(){ int i,j; for(i=1;i<=10;i++){ if(i%3!=0) printf("i=%d\n",i); else continue; //skip to next iteration }} //output – 1 2 4 5 7 8 10