SlideShare a Scribd company logo
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

PDF
MG6088 SOFTWARE PROJECT MANAGEMENT
PPT
7.data types in c#
ODP
Datatype in JavaScript
PPTX
Introduction to c++
PDF
Asp.net state management
PPT
Variables in C Programming
PPTX
Tokens in C++
PPTX
1 unit (oops)
MG6088 SOFTWARE PROJECT MANAGEMENT
7.data types in c#
Datatype in JavaScript
Introduction to c++
Asp.net state management
Variables in C Programming
Tokens in C++
1 unit (oops)

What's hot (20)

PPTX
Javascript operators
PPTX
CSharp Presentation
PPT
Formatted input and output
PDF
State chart diagram
PPTX
virtual function
PPTX
Programming Fundamentals lecture 1
PDF
Python functions
DOCX
Java and its features
PPTX
Dynamic memory allocation in c++
PPT
PPT
Introduction to Basic C programming 01
PPT
Class and object in C++
PPTX
Control Flow Statements
PPTX
data types in C programming
PPTX
Java constructors
PPT
Java applets
PPTX
Basic Data Types in C++
PPTX
Looping statements in C
PDF
Dependency Injection
PPT
Quality Management in Software Engineering SE24
Javascript operators
CSharp Presentation
Formatted input and output
State chart diagram
virtual function
Programming Fundamentals lecture 1
Python functions
Java and its features
Dynamic memory allocation in c++
Introduction to Basic C programming 01
Class and object in C++
Control Flow Statements
data types in C programming
Java constructors
Java applets
Basic Data Types in C++
Looping statements in C
Dependency Injection
Quality Management in Software Engineering SE24
Ad

Similar to Control statements and functions in c (20)

PPTX
Mca i pic u-3 handling input output and control statements
PPTX
handling input output and control statements
PPTX
Btech i pic u-3 handling input output and control statements
PPTX
Diploma ii cfpc u-3 handling input output and control statements
PPTX
CONTROL STMTS.pptx
PPTX
Bsc cs pic u-3 handling input output and control statements
PPTX
C Programming Unit-2
PDF
Controls & Loops in C
PPT
DOCX
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
PPT
2. Control structures with for while and do while.ppt
PDF
4_Decision Making and Branching in C Program.pdf
PPTX
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
PPTX
C PPT.power point presentation about c pro
DOC
Jumping statements
PPT
control-statements, control-statements, control statement
PPTX
C language 2
PPTX
C Programming Language Part 6
PDF
Control structure and Looping statements
PPTX
fundamentals of softweare engeneering and programming in C.pptx
Mca i pic u-3 handling input output and control statements
handling input output and control statements
Btech i pic u-3 handling input output and control statements
Diploma ii cfpc u-3 handling input output and control statements
CONTROL STMTS.pptx
Bsc cs pic u-3 handling input output and control statements
C Programming Unit-2
Controls & Loops in C
C UNIT-2 PREPARED Y M V BRAHMANANDA REDDY
2. Control structures with for while and do while.ppt
4_Decision Making and Branching in C Program.pdf
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
C PPT.power point presentation about c pro
Jumping statements
control-statements, control-statements, control statement
C language 2
C Programming Language Part 6
Control structure and Looping statements
fundamentals of softweare engeneering and programming in C.pptx
Ad

More from vampugani (19)

PPTX
Social media presentation
PPTX
Creating Quick Response(QR) Codes for the OER
PPTX
Arithmetic Computation using 2's Complement Notation
PPTX
Post Graduate Diploma in Computer Applications (PGDCA)
PPTX
Overview of Distributed Systems
PPT
Protection and Security in Operating Systems
PPT
Virtual Memory
PPT
Memory Management in OS
PPT
Process Scheduling
PPT
Processes
PPT
Introduction to OS
PPT
Operating Systems
PPT
Distributed Systems
PPT
Multiprocessor Systems
PPT
File Management in Operating Systems
PPT
Strings in c
PPT
Arrays in c
PPT
Introduction to C Programming
PPT
Introduction to C Programming - I
Social media presentation
Creating Quick Response(QR) Codes for the OER
Arithmetic Computation using 2's Complement Notation
Post Graduate Diploma in Computer Applications (PGDCA)
Overview of Distributed Systems
Protection and Security in Operating Systems
Virtual Memory
Memory Management in OS
Process Scheduling
Processes
Introduction to OS
Operating Systems
Distributed Systems
Multiprocessor Systems
File Management in Operating Systems
Strings in c
Arrays in c
Introduction to C Programming
Introduction to C Programming - I

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PPTX
Lesson notes of climatology university.
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
GDM (1) (1).pptx small presentation for students
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Complications of Minimal Access Surgery at WLH
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Cell Types and Its function , kingdom of life
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Computing-Curriculum for Schools in Ghana
Insiders guide to clinical Medicine.pdf
Lesson notes of climatology university.
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Sports Quiz easy sports quiz sports quiz
PPH.pptx obstetrics and gynecology in nursing
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
GDM (1) (1).pptx small presentation for students
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Complications of Minimal Access Surgery at WLH
Abdominal Access Techniques with Prof. Dr. R K Mishra
Cell Types and Its function , kingdom of life
STATICS OF THE RIGID BODIES Hibbelers.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Final Presentation General Medicine 03-08-2024.pptx
Pre independence Education in Inndia.pdf
Computing-Curriculum for Schools in Ghana

Control statements and functions in c

  • 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.