SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
C_Programming
Part 3
ENG. KEROLES SHENOUDA
1
C Fundamentals
2
IdentifiersKeywords
Data Types
Operators
Comments
Statements
Constants
1.Integer constants
2.Floating-point
constants
3.Character constants
4.String constants
 Control Statements
 if
 switch
 goto
 for loop
 while loop
 do-while loop
 break
 continue
 Nested Loop
 null statement
 expression statement
Arithmetic operators
Relational operators
Logical operators
Assignment operators
Conditional operators
Comma operators
Bitwise Operators
min = (x < y) ? x : y;
Identifier = (test expression)? Expression1: Expression2 ;
int i , j;
i=(j=10,j+20);
A set of expression separated by comma is a valid
constant in the C language
User Defined
enum typedef
Derived
Arrays
structure union
pointer
Primitive/Basic Types
Integer ValuesReal Values
signe
d
unsigned
Identifiers
 Identifiers are the names that are given to various program elements
such as variables, symbolic constants and functions.
 Identifier can be freely named, the following restrictions.
 Alphanumeric characters ( a ~ z , A~Z , 0~9 ) and half underscore ( _ )
can only be used.
 The first character of the first contain letters ( a ~ z , A~Z ) or half
underscore ( _ ) can only be used.
3
Identifiers
 Here are the rules you need to know:
 1. Identifier name must be a sequence of letter and digits, and must begin with a letter.
 2. The underscore character (‘_’) is considered as letter.
 3. Names shouldn't be a keyword (such as int , float, if ,break, for etc)
 4. Both upper-case letter and lower-case letter characters are allowed. However, they're not interchangeable.
 5. No identifier may be keyword.
 6. No special characters, such as semicolon,period,blank space, slash or comma are permitted
 Examples of legal and illegal identifiers follow, first some legal identifiers:
 float _number;
 float a;
 The following are illegal (it's your job to recognize why):
 float :e; float for; float 9PI; float .3.14; float 7g;
4
Keywords
 Keywords are standard identifiers that have standard predefined meaning in C. Keywords
are all lowercase, since uppercase and lowercase characters are not equivalent it's possible
to utilize an uppercase keyword as an identifier but it's not a good programming practice.
 1. Keywords can be used only for their intended purpose.
 2. Keywords can't be used as programmer defined identifier.
 3. The keywords can't be used as names for variables.
 The standard keywords are given below:
5
Controlling Program Flow 6
Conditions 7
Example : Using Conditions
#include "stdio.h"
#include "math.h"
void main()
{
int a = 9;
int b = 8;
int c = 12;
printf("%drn", a>b);
printf("%drn", b>c);
printf("%drn", a<=9);
printf("%drn", a!=9);
printf("%drn", (a-b)>(c-b));
printf("%drn", a>b && c>b);
printf("%drn", a>b && c<b);
printf("%drn", a>b || c<b);
printf("%drn", !(a<b));
printf("%drn", 3 && 0);
printf("%drn", -15 || 0);
printf("%drn", !(-15));
}
8
Example :Using Conditions
#include "stdio.h"
#include "math.h"
void main()
{
int a = 9;
int b = 8;
int c = 12;
printf("%drn", a>b); //prints 1
printf("%drn", b>c); //prints 0
printf("%drn", a<=9); //prints 1
printf("%drn", a!=9); //prints 0
printf("%drn", (a-b)>(c-b)); //prints 0
printf("%drn", a>b && c>b); //prints 1
printf("%drn", a>b && c<b); //prints 0
printf("%drn", a>b || c<b); //prints 1
printf("%drn", !(a<b)); //prints 1
printf("%drn", 3 && 0); //prints 0
printf("%drn", -15 || 0); //prints 1
printf("%drn", !(-15)); //prints 0
}
9
if Statement
if(/*if condition*/)
{
//if body
}
else if(/*else if condition*/)
{
//else if body
}
else if(/*else if condition*/)
{
//else if body
}
else
{
//else body
}
10
Calculate Circle Area or Circumference
11
In this program the user has to choose between calculating circle area or circle
circumference. The choice comes by taking a character from the keyboard using the (getche)
function. If the user presses „a‟ character it proceeds with area calculation and printing. If the
user presses „c‟ character it proceeds with circumference calculation and printing. If the user
presses other letters the program prints an error message.
12
Comparing Three Numbers
13
This program finds the largest value of the three given values.
14
Inline condition / Conditional operators
 Sometimes it is required to take a fast decision inside your statements; this is
called the inline
condition. Following examples illustrate the idea.
15
min = (x < y) ? x : y;
Identifier = (test expression)? Expression1: Expression2 ;
Calculate the Minimum
of Two Numbers
16
17
switch Statement
switch(/*switch expression*/)
{
case /*case value*/:
{
//case body
}
break;
...
...
...
case /* case value*/:
{
//case body
}
break;
default:
{
}
break;
}
18
Calculate
Circle Area or
Circumference
19
for Statement 20
Printing Hello World in a Loop 21
Printing Hello World in a Loop 22
Calculate the Summation of
values between 1 and 99
23
Calculate the Summation of
values between 1 and 99
24
Calculate the Average
Students Degrees
25
calculates the average students degree for any given students
number.
26
while Statement 27
Calculate the Summation of odd values
between 1 and 99
28
Calculate the Average Students Degrees 29
Important:
break
statement is
used to exit
from any loop
type.
do…while Statement 30
Calculate Polynomial Value 31
goto Statement 32
goto Statement 33
break statement
 The break statement is a jump
instruction and can be used inside a
switch construct, for loop,
while loop and do-while loop.
 The execution of break statement
causes immediate exit from the
concern construct and the control is
transferred to the statement
following the loop.
34
break statement
 The break statement is a jump instruction
and can be used inside a switch construct,
for loop, while loop and do-while
loop.
 The execution of break statement causes
immediate exit from the concern construct
and the control is transferred to the
statement following the loop.
35
continue statement
 Continue statement is used to
continue the next iteration of for loop,
while loop and do-while loops. So, the
remaining statements are skipped
within the loop for that particular
iteration.
 Syntax : continue;
36
continue statement
 Continue statement is used to
continue the next iteration of for loop,
while loop and do-while loops. So, the
remaining statements are skipped
within the loop for that particular
iteration.
 Syntax : continue;
37
Nested loop
 In many cases we may use loop statement inside another looping statement.
This type of looping is called nested loop
38
Write a program that produces
the following output:
39
Follow Chapter 3:
Controlling Program
Flow
C PROGRAMMING FOR ENGINEERS, DR. MOHAMED SOBH
40
References 41
 The Case for Learning C as Your First Programming Language
 A Tutorial on Data Representation
 std::printf, std::fprintf, std::sprintf, std::snprintf…..
 C Programming for Engineers, Dr. Mohamed Sobh
 C programming expert.
 fresh2refresh.com/c-programming

Contenu connexe

Tendances

C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageRakesh Roshan
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection StatementsSzeChingChen
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software developmentHattori Sidek
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CSowmya Jyothi
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiSowmyaJyothi3
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrogramanhardryu
 

Tendances (16)

Fortran 90 Basics
Fortran 90 BasicsFortran 90 Basics
Fortran 90 Basics
 
C language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C languageC language Unit 2 Slides, UPTU C language
C language Unit 2 Slides, UPTU C language
 
C language
C languageC language
C language
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
Ch5 Selection Statements
Ch5 Selection StatementsCh5 Selection Statements
Ch5 Selection Statements
 
Ch1 principles of software development
Ch1 principles of software developmentCh1 principles of software development
Ch1 principles of software development
 
C programming part2
C programming part2C programming part2
C programming part2
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Learn C
Learn CLearn C
Learn C
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
C++ for beginners
C++ for beginnersC++ for beginners
C++ for beginners
 
Mycasestudy
MycasestudyMycasestudy
Mycasestudy
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
C language basics
C language basicsC language basics
C language basics
 
Kuliah komputer pemrograman
Kuliah  komputer pemrogramanKuliah  komputer pemrograman
Kuliah komputer pemrograman
 
C programming session7
C programming  session7C programming  session7
C programming session7
 

En vedette (20)

Embedded C programming session10
Embedded C programming  session10Embedded C programming  session10
Embedded C programming session10
 
Automative basics v3
Automative basics v3Automative basics v3
Automative basics v3
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
C programming first_session
C programming first_sessionC programming first_session
C programming first_session
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
K vector embedded_linux_workshop
K vector embedded_linux_workshopK vector embedded_linux_workshop
K vector embedded_linux_workshop
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Microcontroller part 5
Microcontroller part 5Microcontroller part 5
Microcontroller part 5
 
C programming part2
C programming part2C programming part2
C programming part2
 
C programming part4
C programming part4C programming part4
C programming part4
 
Microcontroller part 4
Microcontroller part 4Microcontroller part 4
Microcontroller part 4
 
Microcontroller part 1
Microcontroller part 1Microcontroller part 1
Microcontroller part 1
 
Microcontroller part 7_v1
Microcontroller part 7_v1Microcontroller part 7_v1
Microcontroller part 7_v1
 
Microcontroller part 8_v1
Microcontroller part 8_v1Microcontroller part 8_v1
Microcontroller part 8_v1
 
Microcontroller part 9_v1
Microcontroller part 9_v1Microcontroller part 9_v1
Microcontroller part 9_v1
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Microcontroller part 6_v1
Microcontroller part 6_v1Microcontroller part 6_v1
Microcontroller part 6_v1
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
C programming part2
C programming part2C programming part2
C programming part2
 

Similaire à C programming session3

C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYRajeshkumar Reddy
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxKrishanPalSingh39
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)sachindane
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chapthuhiendtk4
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 SlidesRakesh Roshan
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02CIMAP
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing TutorialMahira Banu
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoMark John Lado, MIT
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentationnadim akber
 

Similaire à C programming session3 (20)

C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDYC UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
 
presentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptxpresentation_c_basics_1589366177_381682.pptx
presentation_c_basics_1589366177_381682.pptx
 
C Language (All Concept)
C Language (All Concept)C Language (All Concept)
C Language (All Concept)
 
1584503386 1st chap
1584503386 1st chap1584503386 1st chap
1584503386 1st chap
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Unit 1
Unit 1Unit 1
Unit 1
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Programming in C
Programming in CProgramming in C
Programming in C
 
What is c
What is cWhat is c
What is c
 
C programming
C programmingC programming
C programming
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Programming-in-C
Programming-in-CProgramming-in-C
Programming-in-C
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Introduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John LadoIntroduction to C Language - Version 1.0 by Mark John Lado
Introduction to C Language - Version 1.0 by Mark John Lado
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentation
 

Plus de Keroles karam khalil

Plus de Keroles karam khalil (20)

C basics quiz part 1_solution
C basics quiz part 1_solutionC basics quiz part 1_solution
C basics quiz part 1_solution
 
Autosar Basics hand book_v1
Autosar Basics  hand book_v1Autosar Basics  hand book_v1
Autosar Basics hand book_v1
 
Automotive embedded systems part6 v2
Automotive embedded systems part6 v2Automotive embedded systems part6 v2
Automotive embedded systems part6 v2
 
Automotive embedded systems part5 v2
Automotive embedded systems part5 v2Automotive embedded systems part5 v2
Automotive embedded systems part5 v2
 
EMBEDDED C
EMBEDDED CEMBEDDED C
EMBEDDED C
 
Automotive embedded systems part7 v1
Automotive embedded systems part7 v1Automotive embedded systems part7 v1
Automotive embedded systems part7 v1
 
Automotive embedded systems part6 v1
Automotive embedded systems part6 v1Automotive embedded systems part6 v1
Automotive embedded systems part6 v1
 
Automotive embedded systems part5 v1
Automotive embedded systems part5 v1Automotive embedded systems part5 v1
Automotive embedded systems part5 v1
 
Automotive embedded systems part4 v1
Automotive embedded systems part4 v1Automotive embedded systems part4 v1
Automotive embedded systems part4 v1
 
Automotive embedded systems part3 v1
Automotive embedded systems part3 v1Automotive embedded systems part3 v1
Automotive embedded systems part3 v1
 
Automotive embedded systems part2 v1
Automotive embedded systems part2 v1Automotive embedded systems part2 v1
Automotive embedded systems part2 v1
 
Automotive embedded systems part1 v1
Automotive embedded systems part1 v1Automotive embedded systems part1 v1
Automotive embedded systems part1 v1
 
Automotive embedded systems part8 v1
Automotive embedded systems part8 v1Automotive embedded systems part8 v1
Automotive embedded systems part8 v1
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C programming session10
C programming  session10C programming  session10
C programming session10
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
Quiz 10
Quiz 10Quiz 10
Quiz 10
 
Homework 6
Homework 6Homework 6
Homework 6
 
Homework 5 solution
Homework 5 solutionHomework 5 solution
Homework 5 solution
 
Notes part7
Notes part7Notes part7
Notes part7
 

Dernier

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 

Dernier (20)

THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 

C programming session3

  • 2. C Fundamentals 2 IdentifiersKeywords Data Types Operators Comments Statements Constants 1.Integer constants 2.Floating-point constants 3.Character constants 4.String constants  Control Statements  if  switch  goto  for loop  while loop  do-while loop  break  continue  Nested Loop  null statement  expression statement Arithmetic operators Relational operators Logical operators Assignment operators Conditional operators Comma operators Bitwise Operators min = (x < y) ? x : y; Identifier = (test expression)? Expression1: Expression2 ; int i , j; i=(j=10,j+20); A set of expression separated by comma is a valid constant in the C language User Defined enum typedef Derived Arrays structure union pointer Primitive/Basic Types Integer ValuesReal Values signe d unsigned
  • 3. Identifiers  Identifiers are the names that are given to various program elements such as variables, symbolic constants and functions.  Identifier can be freely named, the following restrictions.  Alphanumeric characters ( a ~ z , A~Z , 0~9 ) and half underscore ( _ ) can only be used.  The first character of the first contain letters ( a ~ z , A~Z ) or half underscore ( _ ) can only be used. 3
  • 4. Identifiers  Here are the rules you need to know:  1. Identifier name must be a sequence of letter and digits, and must begin with a letter.  2. The underscore character (‘_’) is considered as letter.  3. Names shouldn't be a keyword (such as int , float, if ,break, for etc)  4. Both upper-case letter and lower-case letter characters are allowed. However, they're not interchangeable.  5. No identifier may be keyword.  6. No special characters, such as semicolon,period,blank space, slash or comma are permitted  Examples of legal and illegal identifiers follow, first some legal identifiers:  float _number;  float a;  The following are illegal (it's your job to recognize why):  float :e; float for; float 9PI; float .3.14; float 7g; 4
  • 5. Keywords  Keywords are standard identifiers that have standard predefined meaning in C. Keywords are all lowercase, since uppercase and lowercase characters are not equivalent it's possible to utilize an uppercase keyword as an identifier but it's not a good programming practice.  1. Keywords can be used only for their intended purpose.  2. Keywords can't be used as programmer defined identifier.  3. The keywords can't be used as names for variables.  The standard keywords are given below: 5
  • 8. Example : Using Conditions #include "stdio.h" #include "math.h" void main() { int a = 9; int b = 8; int c = 12; printf("%drn", a>b); printf("%drn", b>c); printf("%drn", a<=9); printf("%drn", a!=9); printf("%drn", (a-b)>(c-b)); printf("%drn", a>b && c>b); printf("%drn", a>b && c<b); printf("%drn", a>b || c<b); printf("%drn", !(a<b)); printf("%drn", 3 && 0); printf("%drn", -15 || 0); printf("%drn", !(-15)); } 8
  • 9. Example :Using Conditions #include "stdio.h" #include "math.h" void main() { int a = 9; int b = 8; int c = 12; printf("%drn", a>b); //prints 1 printf("%drn", b>c); //prints 0 printf("%drn", a<=9); //prints 1 printf("%drn", a!=9); //prints 0 printf("%drn", (a-b)>(c-b)); //prints 0 printf("%drn", a>b && c>b); //prints 1 printf("%drn", a>b && c<b); //prints 0 printf("%drn", a>b || c<b); //prints 1 printf("%drn", !(a<b)); //prints 1 printf("%drn", 3 && 0); //prints 0 printf("%drn", -15 || 0); //prints 1 printf("%drn", !(-15)); //prints 0 } 9
  • 10. if Statement if(/*if condition*/) { //if body } else if(/*else if condition*/) { //else if body } else if(/*else if condition*/) { //else if body } else { //else body } 10
  • 11. Calculate Circle Area or Circumference 11 In this program the user has to choose between calculating circle area or circle circumference. The choice comes by taking a character from the keyboard using the (getche) function. If the user presses „a‟ character it proceeds with area calculation and printing. If the user presses „c‟ character it proceeds with circumference calculation and printing. If the user presses other letters the program prints an error message.
  • 12. 12
  • 13. Comparing Three Numbers 13 This program finds the largest value of the three given values.
  • 14. 14
  • 15. Inline condition / Conditional operators  Sometimes it is required to take a fast decision inside your statements; this is called the inline condition. Following examples illustrate the idea. 15 min = (x < y) ? x : y; Identifier = (test expression)? Expression1: Expression2 ;
  • 16. Calculate the Minimum of Two Numbers 16
  • 17. 17
  • 18. switch Statement switch(/*switch expression*/) { case /*case value*/: { //case body } break; ... ... ... case /* case value*/: { //case body } break; default: { } break; } 18
  • 21. Printing Hello World in a Loop 21
  • 22. Printing Hello World in a Loop 22
  • 23. Calculate the Summation of values between 1 and 99 23
  • 24. Calculate the Summation of values between 1 and 99 24
  • 25. Calculate the Average Students Degrees 25 calculates the average students degree for any given students number.
  • 26. 26
  • 28. Calculate the Summation of odd values between 1 and 99 28
  • 29. Calculate the Average Students Degrees 29 Important: break statement is used to exit from any loop type.
  • 34. break statement  The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop.  The execution of break statement causes immediate exit from the concern construct and the control is transferred to the statement following the loop. 34
  • 35. break statement  The break statement is a jump instruction and can be used inside a switch construct, for loop, while loop and do-while loop.  The execution of break statement causes immediate exit from the concern construct and the control is transferred to the statement following the loop. 35
  • 36. continue statement  Continue statement is used to continue the next iteration of for loop, while loop and do-while loops. So, the remaining statements are skipped within the loop for that particular iteration.  Syntax : continue; 36
  • 37. continue statement  Continue statement is used to continue the next iteration of for loop, while loop and do-while loops. So, the remaining statements are skipped within the loop for that particular iteration.  Syntax : continue; 37
  • 38. Nested loop  In many cases we may use loop statement inside another looping statement. This type of looping is called nested loop 38
  • 39. Write a program that produces the following output: 39
  • 40. Follow Chapter 3: Controlling Program Flow C PROGRAMMING FOR ENGINEERS, DR. MOHAMED SOBH 40
  • 41. References 41  The Case for Learning C as Your First Programming Language  A Tutorial on Data Representation  std::printf, std::fprintf, std::sprintf, std::snprintf…..  C Programming for Engineers, Dr. Mohamed Sobh  C programming expert.  fresh2refresh.com/c-programming