SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
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

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Andere mochten auch (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Keroles karam khalil

Mehr von 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
 

Kürzlich hochgeladen

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 

Kürzlich hochgeladen (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 

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