SlideShare ist ein Scribd-Unternehmen logo
1 von 39
OPERATOR & CONTROL STATEMENT
IN
‘C’
Arithmetic operator are used for mathematical calculation
these operator are binary operator that work with integer
floating point number and every character.
Arithmetical operator are:
Operator Meaning
+ Addition
- Subtraction
* Multiplication
/ Division
% Module division
:
Relational operator are used to compare two operands.
Operands may be variable, constant or expression.
Operator Meaning
< Is less than
<= Is less than equal to
> Is greater than
>= Is greater than equal to
== Equal to
!= is not equal to
main()
{
int a=10,b=20,c=30,d,e;
d=a>b;
e=b<=c;
printf(“%d %d”,d,e);
getch();
}
Output:-
0 1
Are used to combine (compare) two or more condition.
Logical Operator are:-
Operator Meaning
&& Logical AND
|| Logical OR
! Logical NOT
Types of operator:-
Logical AND compare two operands and return 1if both
condition are true else return 0 (false)
Logical OR compare two operand and return 1 if any one
condition true.
Example:-
Condition AND OR
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1
Logical NOT if the condition is true result is false and if
the condition is false result true .
Example:-
Condition NOT
0 1
1 0
Assignment Operators:-
Assignment operator are used to assign the value or
an expression or a value of a variable to another variable
a 8=
Expression
Assignment
operator
Unary operator is also called Increments & decrement
operator. The increment operator (++) adder on to the
variable and decrement (- -) subtract one from the variable.
There are following unary operator
Operator Meaning
++x Pre increment
- -x Pre decrement
x++ Post increment
X- - Post decrement
The conditional operator is ternary operator,
which operates On the three operands.
Example:-
main()
{
int a=10,b=5,big;
big=a>b ? a:b;
printf(“Big is %d”,big);
getch();
}
Output is:-
10
Bitwise Operator:-
Are used by the programmer to
communicate directly with the
hardware.These operator are used for
designing bit or shifting them either right to
left, left to right.
Example:- Operator Meaning
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
<< Left shift
>> Right shift
Equality operator:-
Equality operator is used for compression between two
operands these operator.
Example:-
Operator Meaning
== Equal to
!= Not equal to
Decision
control
statement
Iteration
statement
Transfer
statement
Decision Control statement:-
Decision control statement disrupt or alter the
sequential execution of the statement of the program
depending on the test condition in program
Types of Decision control statement:-
Decision
control
statement
1. If
statement
3. Switch
statement
4. Go To
statement
2. If else
statement
The If statement is a powerful decision making statement
and is used to control the flow of execution of statement.
condition
Block of if
Next statement
STOP
FALSE
TRUE
main()
{
int a;
printf(“enter value of a”);
scanf(“%d”,&a);
if(a>25)
{
printf(“no.is greater than 25”);
}
printf(“n bye”);
getch();
}
condition
Block of if
Next statement
STOP
FALSE
TRUE
Block of else
If the condition is true the true block is execute otherwise
False block is execute.
main()
{
int n,c;
printf(“n enter value of n”);
scanf(“%d”,&n);
c=n%2;
if(c==0)
printf(“no is even”);
else
printf(“no is odd”);
getch();
}
What Is Else If Ladder:
If we are having different - different test conditions with different - different statements,
then for these kind of programming we need else if ladder
Syntax Of Else If Leader:
---------------------------------------------------------------------
if(test_condition1)
{
statement 1;
}
else if(test_condition2)
{
statement 2;
}
else if(test_condition3)
{
statement 3;
}
else if(test_condition4)
{
statement 4;
}
else
{
}
void main ( )
{
int num = 10 ;
if ( num > 0 )
printf ("n Number is Positive");
else if ( num < 0 )
printf ("n Number is Negative");
else printf ("n Number is Zero");
}
• Depending on the position of control
statement in c,control structure may be
classified
• Entry_ controlled loop
• Exit _controlled loop
False
true
Entry controlled loop exit controlled loop
Test
conditio
n ?
Body of the
loop
Body of the
loop
Test
conditio
n ?
• C language provides three constructs for
perfoming loop operations
• While statement
• Do statements
• For statements
While(test condition)
{
body of the loop
}
………………………
………………………
int_sum=0;
int_n=1;
while(int_n<=10)
{
int_sum=int_sum+int_n;
int_n=int_n+1;
}
printf(“sum=%dn”,int_sum);
…………………………………………..
Do statement
do
{
Body of the loop
}
While(test condition)
int_i=1;
int_sum=0;
do
{
int_sum=int_sum+I
i=i+2;
}
while(sum<40||i<10);
printf(“%d %dn,I,sum);
For statements
For(intialization;testcondition;icrement)
{
body of the loop
}
• Intialization of control variable done
first using assignment statement
• The value of control variable tested
using test condition,ie reletional
expression such as i>10,that determine
when the loop will exit
• If the condition is true ,the body of
loop executed,otherwise terminated
int_sum=0;
for(int_n=1;int_n<=10;int_n++)
{
int_sum=int_sum+int_n;
}
printf(“sum=%dn”,int_sum);
Nesting of for loop
For(i=0;i<n;i++)
{
………………………………
For(j=0;j<n-1;j++)
{
………………………………
}
}
Jumping out of a loop
• Exit from a loop using break statement
if a break statement encounteredd in a
loop,the loop will immidiatly exited and the
program continues with the statement
immidiatly following loop;ie break will exit
only a single loop
Eg:
while(test condition)
{
……………………………..
………………………………
if(condition)
break;
Skipping a part of loop
Another statement ‘continue’,
• It tells the compiler skip the following statements
and continue with next iteration
Eg:
While (test condition)
{
………………………..
If(…………)
Continue;
Switch statement is a multi-way decision making statement
which selects one of the several alternative based on the value
of integer variable or expression.
Syntax :-
switch(expression)
{
case constant : statement;
break;
default : statement;
}
main()
{
char choice;
printf(“enter any alphabet”);
scanf(“%d”,& choice);
switch(choice)
{
case ‘a’:
printf(“this is a vowel n”);
break;
case ‘e’ :
printf(“this is a vowel n”);
break;
case ‘i’ :
printf(“this is a vowel n”);
break;
case ‘o’ :
printf(“this is a vowel n”);
break;
case ‘u’ :
printf(“this is a vowel n”);
break;
default :
printf(“this is not a vowel”);
getch();
}
}
Go To statement
A GO TO statement can cause program control to end up anywhere in the
program unconditionally.
Example :-
main()
{
int i=1;
up : printf(“Hello To C”)
i++;
If (i<=5)
goto up
getch();
}

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (20)

While , For , Do-While Loop
While , For , Do-While LoopWhile , For , Do-While Loop
While , For , Do-While Loop
 
Structure in C
Structure in CStructure in C
Structure in C
 
Loops in C Programming Language
Loops in C Programming LanguageLoops in C Programming Language
Loops in C Programming Language
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
Operators in java
Operators in javaOperators in java
Operators in java
 
C if else
C if elseC if else
C if else
 
String functions in C
String functions in CString functions in C
String functions in C
 
Strings
StringsStrings
Strings
 
Operator.ppt
Operator.pptOperator.ppt
Operator.ppt
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Break and continue
Break and continueBreak and continue
Break and continue
 
Decision Making Statement in C ppt
Decision Making Statement in C pptDecision Making Statement in C ppt
Decision Making Statement in C ppt
 
Loops c++
Loops c++Loops c++
Loops c++
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
structure and union
structure and unionstructure and union
structure and union
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 

Ähnlich wie Control statements in c

operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c languageshhanks
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7REHAN IJAZ
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++Neeru Mittal
 
03a control structures
03a   control structures03a   control structures
03a control structuresManzoor ALam
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsTech
 
3. control statements
3. control statements3. control statements
3. control statementsamar kakde
 
C operators
C operatorsC operators
C operatorsGPERI
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsDhivyaSubramaniyam
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cSowmya Jyothi
 

Ähnlich wie Control statements in c (20)

Programming for Problem Solving
Programming for Problem SolvingProgramming for Problem Solving
Programming for Problem Solving
 
operators and control statements in c language
operators and control statements in c languageoperators and control statements in c language
operators and control statements in c language
 
C PRESENTATION.pptx
C PRESENTATION.pptxC PRESENTATION.pptx
C PRESENTATION.pptx
 
Programming Fundamentals lecture 7
Programming Fundamentals lecture 7Programming Fundamentals lecture 7
Programming Fundamentals lecture 7
 
Operators and expressions in C++
Operators and expressions in C++Operators and expressions in C++
Operators and expressions in C++
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
C – operators and expressions
C – operators and expressionsC – operators and expressions
C – operators and expressions
 
03a control structures
03a   control structures03a   control structures
03a control structures
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
operators.pptx
operators.pptxoperators.pptx
operators.pptx
 
The Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming ConceptsThe Three Basic Selection Structures in C++ Programming Concepts
The Three Basic Selection Structures in C++ Programming Concepts
 
Theory3
Theory3Theory3
Theory3
 
C operator and expression
C operator and expressionC operator and expression
C operator and expression
 
cprogrammingoperator.ppt
cprogrammingoperator.pptcprogrammingoperator.ppt
cprogrammingoperator.ppt
 
Lecture 3
Lecture 3Lecture 3
Lecture 3
 
3. control statements
3. control statements3. control statements
3. control statements
 
C operators
C operatorsC operators
C operators
 
Java unit 3
Java unit 3Java unit 3
Java unit 3
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 

Kürzlich hochgeladen

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
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.pdfAdmir Softic
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
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
 
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
 
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 ModeThiyagu K
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
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
 

Kürzlich hochgeladen (20)

General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
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
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
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"
 
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
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
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..
 
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
 
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
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
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
 

Control statements in c