SlideShare a Scribd company logo
1 of 15
Control Statements and
Functions in C
V.V.Subrahmanyam,
Sr. Lecturer,
SOCIS, IGNOU
Date: 04-02-07
Time: 1-00 to 1-45
Control Statements
Branching:
 The if statement
 If – Else statement
Looping:
 While Statement
 Do-while statement
 For Statement
Switch statement
If statement
If (expr) statement
Example: if (x<0)
printf (“ %d”, x);
If – else statement
If (expr) statement1;
else
statement2;
Example:
if (status == ‘s”)
tax = 0.20 * pay;
else
tax = 0.14 * pay;
Nested if - else
if e1 if e2 s1
else s2
else if e3 s3
else s4
While statement
while (expr)
{ statement(s); }
Example: int digit=9;
while(digit <= 9)
{
printf(“%dn”, digit);
++digit;
}
Do – while statement
Do statement while (expr);
Example:
{
int digit = 10;
do
printf(“%dn”, digit);
while (digit <= 9);
}
For loop
For (expr1; expr2; expr3) statement
Example:
int I;
for (i=0;i<=10; i++) {
printf(“%d”, i);
}
Break statement
It can be used within a for, while , do-
while, or a switch statement.
It is used to terminate a loop or to exit
from a switch statement in a convenient
way when a condition is met, if any
error or irregular condition is detected.
Continue statement
It is used to bypass the remainder of the
current pass through a loop. The loop
does not terminate when a continue
statements is encountered. Rather, the
remaining loop statements are skipped
and the computation proceeds directly
to the next pass through the loop.
Goto statement
The goto statement is used to alter the normal
sequence of program execution by
transferring control to some other part of the
program.
goto label;
---
---
Label: statement;
Functions
The use of user-defined functions
allows a large program to be broken
down into a number of smaller, self-
contained components, each of which
has some unique, identifiable purpose.
The C program can be modularized
through the intelligent use of such
functions.
Avoids the need of repeated
programming of the same instructions.
Types of functions
Functions with no parameters and no
return value
Functions with parameters and no
return value
Functions with parameters and with
return value.
Function Declaration
Prototype declaration at the declaration
part.
Data-type fname(type1 arg1, type2 arg2);
Function definition
Actual statements of the function to
solve the specified task.

More Related Content

What's hot

What's hot (19)

C++ programming Unit 5 flow of control
C++ programming Unit 5 flow of controlC++ programming Unit 5 flow of control
C++ programming Unit 5 flow of control
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Control structure in c
Control structure in cControl structure in c
Control structure in c
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
[ITP - Lecture 10] Switch Statement, Break and Continue Statement in C/C++
 
Elements of c program....by thanveer danish
Elements of c program....by thanveer danishElements of c program....by thanveer danish
Elements of c program....by thanveer danish
 
Decision making statements in C programming
Decision making statements in C programmingDecision making statements in C programming
Decision making statements in C programming
 
Control statements
Control statementsControl statements
Control statements
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
Selection Statements in C Programming
Selection Statements in C ProgrammingSelection Statements in C Programming
Selection Statements in C Programming
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 

Similar to Introduction to C Programming

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
Rajeshkumar Reddy
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
chintupro9
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
yasir_cesc
 

Similar to Introduction to C Programming (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
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt2. Control structures with for while and do while.ppt
2. Control structures with for while and do while.ppt
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
C Programming Language Part 6
C Programming Language Part 6C Programming Language Part 6
C Programming Language Part 6
 
computer programming and utilization
computer programming and utilizationcomputer programming and utilization
computer programming and utilization
 
Session 3
Session 3Session 3
Session 3
 
C lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshareC lecture 4 nested loops and jumping statements slideshare
C lecture 4 nested loops and jumping statements slideshare
 
C statements.ppt presentation in c language
C statements.ppt presentation in c languageC statements.ppt presentation in c language
C statements.ppt presentation in c language
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
C programming session3
C programming  session3C programming  session3
C programming session3
 
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow controlIntroduction to computer programming (C)-CSC1205_Lec5_Flow control
Introduction to computer programming (C)-CSC1205_Lec5_Flow control
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 

More from vampugani

Post Graduate Diploma in Computer Applications (PGDCA)
Post Graduate Diploma in Computer Applications (PGDCA)Post Graduate Diploma in Computer Applications (PGDCA)
Post Graduate Diploma in Computer Applications (PGDCA)
vampugani
 

More from vampugani (18)

Social media presentation
Social media presentationSocial media presentation
Social media presentation
 
Creating Quick Response(QR) Codes for the OER
Creating Quick Response(QR) Codes for the OERCreating Quick Response(QR) Codes for the OER
Creating Quick Response(QR) Codes for the OER
 
Arithmetic Computation using 2's Complement Notation
Arithmetic Computation using 2's Complement NotationArithmetic Computation using 2's Complement Notation
Arithmetic Computation using 2's Complement Notation
 
Post Graduate Diploma in Computer Applications (PGDCA)
Post Graduate Diploma in Computer Applications (PGDCA)Post Graduate Diploma in Computer Applications (PGDCA)
Post Graduate Diploma in Computer Applications (PGDCA)
 
Overview of Distributed Systems
Overview of Distributed SystemsOverview of Distributed Systems
Overview of Distributed Systems
 
Protection and Security in Operating Systems
Protection and Security in Operating SystemsProtection and Security in Operating Systems
Protection and Security in Operating Systems
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Memory Management in OS
Memory Management in OSMemory Management in OS
Memory Management in OS
 
Process Scheduling
Process SchedulingProcess Scheduling
Process Scheduling
 
Processes
ProcessesProcesses
Processes
 
Introduction to OS
Introduction to OSIntroduction to OS
Introduction to OS
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Distributed Systems
Distributed SystemsDistributed Systems
Distributed Systems
 
Multiprocessor Systems
Multiprocessor SystemsMultiprocessor Systems
Multiprocessor Systems
 
File Management in Operating Systems
File Management in Operating SystemsFile Management in Operating Systems
File Management in Operating Systems
 
Strings in c
Strings in cStrings in c
Strings in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Introduction to C Programming - I
Introduction to C Programming - I Introduction to C Programming - I
Introduction to C Programming - I
 

Recently uploaded

Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Recently uploaded (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
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
 
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
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 

Introduction to C Programming

  • 1. Control Statements and Functions in C V.V.Subrahmanyam, Sr. Lecturer, SOCIS, IGNOU Date: 04-02-07 Time: 1-00 to 1-45
  • 2. Control Statements Branching:  The if statement  If – Else statement Looping:  While Statement  Do-while statement  For Statement Switch statement
  • 3. If statement If (expr) statement Example: if (x<0) printf (“ %d”, x);
  • 4. If – else statement If (expr) statement1; else statement2; Example: if (status == ‘s”) tax = 0.20 * pay; else tax = 0.14 * pay;
  • 5. Nested if - else if e1 if e2 s1 else s2 else if e3 s3 else s4
  • 6. While statement while (expr) { statement(s); } Example: int digit=9; while(digit <= 9) { printf(“%dn”, digit); ++digit; }
  • 7. Do – while statement Do statement while (expr); Example: { int digit = 10; do printf(“%dn”, digit); while (digit <= 9); }
  • 8. For loop For (expr1; expr2; expr3) statement Example: int I; for (i=0;i<=10; i++) { printf(“%d”, i); }
  • 9. Break statement It can be used within a for, while , do- while, or a switch statement. It is used to terminate a loop or to exit from a switch statement in a convenient way when a condition is met, if any error or irregular condition is detected.
  • 10. Continue statement It is used to bypass the remainder of the current pass through a loop. The loop does not terminate when a continue statements is encountered. Rather, the remaining loop statements are skipped and the computation proceeds directly to the next pass through the loop.
  • 11. Goto statement The goto statement is used to alter the normal sequence of program execution by transferring control to some other part of the program. goto label; --- --- Label: statement;
  • 12. Functions The use of user-defined functions allows a large program to be broken down into a number of smaller, self- contained components, each of which has some unique, identifiable purpose. The C program can be modularized through the intelligent use of such functions. Avoids the need of repeated programming of the same instructions.
  • 13. Types of functions Functions with no parameters and no return value Functions with parameters and no return value Functions with parameters and with return value.
  • 14. Function Declaration Prototype declaration at the declaration part. Data-type fname(type1 arg1, type2 arg2);
  • 15. Function definition Actual statements of the function to solve the specified task.