SlideShare a Scribd company logo
GANDHINAGAR INSTITUTE
OF TECHNOLOGY
SUBJECT : COMPUTER PROGRAMMING AND
UTILIZATION(2110003)
TOPIC : “Control Structures in C .”
Guided by : Prof. Archana Singh
MADE BY:-JAYDEV PATEL(150120119127)
KRUNAL PATEL(150120119128)
JAIMIN PATEL(150120119126)
CONTENT
• Introduction
• Decision Making Statement
i. If else statement
ii. Ladder if else
iii. Switch statement
• Looping
i. While loop
ii. do-while loop
iii. For loop
iv. Nesting loop
v. Flow breaking statement
Introduction
• The important and essential part of a
programming language is their control
structures.
1. Sequence
2. Decision
3. Looping
Decision making statement
• This is same as choosing one of the alternatives
out of the two alternatives available.
• There are various types of decision making
statements:-
i. If else statement
ii. Ladder if-else
iii. Switch
iv. goto
If-else statement
• The syntax of if else statement is:
if(condition)
statement 1;
else
statement 2;
Flow chart of if else statement
If-else statement
• Here the condition is represented by relational or
logical expression.
• If condition is true, then statement 1 is executed and if
condition is false statement 2 is executed.
• A compound statement must be enclosedin pair of
braces{}.
• Enclosing in a single statement is not compulsory.
• The else part is is optional. The if statement without
else looks like:-
if(condition)
statement;
Write a program to print minimum of
two integers.
#include<stdio.h>
Void main()
{
Int x,y,min;
Printf(“enter two integers”);
Scanf(“%d %d”,&x,&y);
If(x<y)
min=x;
Else
min=y;
Printf(“minimum is:%dn”,min);
}
• Output:-
enter two integers
10 6
Minimum is :6
Ladder if-else
• The if else is used for two way decision where we select one of the
alternative.
• But for more than that c supports more multiple if-else or ladder if else for
this purpose.
• The syntax of multiple if else is:-
• If(condition 1)
statement1;
else if(condition2)
statement2;
.
.
else if(conditionN)
statementN;
else
default_statement;
Ladder if else
• The condition1,condition2,…,conditionN are
represented in logical or relational
expression s .
• if the first condition is true than statement1
will be executed or the other conditions will
be evaluated till the correct condition is
found.
• If the true condition is not found than at last
the default statement will be executed.
Write a program to compute the
electricity bill.
#include<stdio.h>
Void main()
{
Int units;
Float ucharge,fcharge,gtax,meter_rent= 25.0,total;
Printf(“enter number of units consumed”);
Scanf(“%d”,units);
If(units<=50)
Ucharge=0.5*units;
Else if(units<=100)
Ucharge=50*0.5+(units-50)*0.75;
Else if(units<=200)
Ucharge=50*0.5+50*0.75+(units-100)*1.00;
Else
Ucharge=50*0.5+50*0.75+100*1.00+(units-200)*1.50;
Fcharge=0.40*ucharge;
Gtax=0.10*(ucharge+fcharge);
Total=ucharge+fcharge+gtax+meter_rent;
Printf(“total bill: %fn”,total);
}
Output
Enter the value of units consumed
85
Total bill : 103.925003
Switch statement
• The switch in C is a multi-choice statement.
• It provides one choice for each value of variable expression.
• The syntax of switch is given below:
Switch(variable) {
Case label1: statement_block1;
break;
Case label2: statement_block2;
break;
.
.
default: default_block
Switch statement
• Lebel1 ,label2,…. Show the possible value of
the variable or expression.
• After every statement block there is a break.
• Break sends control to the next switch
statement.
• The last choice is default which is chosen
when the value of expression does not match
to any of the expression.
• But default is optional.
Write a program to perform arithmetic
operations.
#include<stdio.h>
#include<conio.h>
Void main()
{
Int choice,a,b;
Clrscr();
Printf(“1. add n”);
Printf(“2. subn”);
Printf(“3. muln”);
Printf(“4. divn”);
Printf(“Enter your choice:”);
Scanf(“%d”,&choice);
Printf(“enter two numbers”);
Scanf(“%d %d “,&a,&b);
Switch(choice) {
Case 1: printf(“answer=%dn”,a+b);
break;
Case 2: printf(“answer=%dn”,a-b);
break;
Case 3: printf(“answer=%dn”,a*b);
break;
Case4 : printf(“answer=%dn”a/b);
break;
Default: break;
}
}
Output
1. Add
2. Sub
3. Mul
4. Div
Enter your choice :1
Enter two numbers
23 35
Answer =58
Goto statement
• The goto statement in C programming is used
to transfer the control unconditionally from
one part of program to another.
• The goto statement can be dangerous to
programming languages.
• The syntax is
Goto label;
Write a program to print the sum of 1
to N using goto statement.
#include<stdio.h>
Void main()
{
Int i=1,sum=0,n;
Printf(“Enter value of N”);
Scanf(“%d”,&n);
next:
Sum= sum+I;
i+ =1;
If(I <= n )
Goto next;
Printf(“sum = %dn”,sum);
}
Output
Enter the value of N
4
Sum = 10
Looping
• A looping is an important control structure in
higher level programming language.
• The objective of looping is to provide
repetition of the part of the program i.e. block
of statements in a program, number of times.
Types of loop
• There are two types of loop:
1. Entry control
2. Exit control
• In entry control loop the condition is checked
first and then the body is executed, while in
exit control the body is excuted first and
then the condition is checked.
While loop
• The syntax of while loop is:
While(condition)
{
body;
}
While loop
• Here the condition is evaluated first and then
the body is executed. After executing the body
the condition is evaluated again and if it is
true body is executed again. This process is
repeated as long as the condition is true.
• While loop is a entry control loop.
• It is not necessary to enclose body of loop in
pair of {} if body contains single statement.
Write program to compute the sum of
following series.
1²+2²+…+10²
#include<stdio.h>
Void main()
{
Int sum=0,n=1;
While(n<=10)
{
sum = = n*n;
n++;
}
Printf(“sum of series :%dn”,sum);
}
Output
Sum of series : 385
Do-while loop
• The syntax of do-while loop is:
do{
Body;
} while (condition);
Do-while loop
• In do-while first the body is executed and then
the condition is checked. If the condition is
true the body is again executed. The body is
executed as long as the condition is true.
• Do-while loop is a exit control loop.
• This ensures the body is atleast once executed
even if the condition is false.
For loop
• The syntax of for loop is :
For(<e1>;<e2>;<e3>)
{
body;
}
For loop
• <e1> is initialization of variable by initial
values.<e1> executes only once when we
enter in loop. If they are more than one they
should be separated by commas.
• <e2> is the condition and the if it is true, then
the control enters into the body of the loop
and executes the statement in body.
• After executing the body of the loop, <e3> is
executed which modifies the variable.
Write a program to print the
multiplication table for a given number
N.
#include<stdio.h>
Void main()
{
Int I,n;
Printf(“enter a number”);
Scanf(“%d”,&n);
Printf(“Table->n”);
For(i=1,1<=10;i++)
Printf(“%4d*%2d=%4dn’,n,I,n*i);
}
Output
Enter a number
3
Table->
3*1=3
3*2=6
3*3=9
3*4=12
3*5=15
3*6=18
3*7=21
3*8=24
3*9=27
3*10=30
Nesting of loops
• Loop inside loop is called nested loops. For example,
…
…
For( )
{
…..
for( )
{
…….
……..
}
…….
}
…….
…….
Nesting of loops
Write a program to print the
triangle.for n=5
#include<stdio.h>
Void main()
{
Int n,l,j;
Printf(“enter number of lines”);
Scanf(“%d”,&n);
Printf(“triangle ->n”);
For(l=1;l<=n;l++)
{for(j=1;j<=1;j++)
Printf(“%d”,j);
Printf(“n”);
}
}
Output
Enter number of lines
5
Triangle->
1
12
123
1234
12345
Thank you

More Related Content

What's hot

Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Control Structures
Control StructuresControl Structures
Control StructuresGhaffar Khan
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
Komal Kotak
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
Haard Shah
 
Control structure
Control structureControl structure
Control structure
Samsil Arefin
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
tanmaymodi4
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
Thesis Scientist Private Limited
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
Way2itech
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
Anil Kumar
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
Tarun Sharma
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
Bipul Chandra Kar
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
SHRIRANG PINJARKAR
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
rajshreemuthiah
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
Zohaib Ahmed
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
vampugani
 
Behavioral modeling
Behavioral modelingBehavioral modeling
Behavioral modeling
dennis gookyi
 
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
Tech
 

What's hot (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Control Structures
Control StructuresControl Structures
Control Structures
 
Control structure of c
Control structure of cControl structure of c
Control structure of c
 
C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Control structure
Control structureControl structure
Control structure
 
Operators and expressions in c language
Operators and expressions in c languageOperators and expressions in c language
Operators and expressions in c language
 
Controls & Loops in C
Controls & Loops in C Controls & Loops in C
Controls & Loops in C
 
9. statements (conditional statements)
9. statements (conditional statements)9. statements (conditional statements)
9. statements (conditional statements)
 
Control structure C++
Control structure C++Control structure C++
Control structure C++
 
Control structures in c
Control structures in cControl structures in c
Control structures in c
 
Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Peterson Critical Section Problem Solution
Peterson Critical Section Problem SolutionPeterson Critical Section Problem Solution
Peterson Critical Section Problem Solution
 
C++ chapter 4
C++ chapter 4C++ chapter 4
C++ chapter 4
 
Control statement in c
Control statement in cControl statement in c
Control statement in c
 
Control and conditional statements
Control and conditional statementsControl and conditional statements
Control and conditional statements
 
C++ decision making
C++ decision makingC++ decision making
C++ decision making
 
Control statements and functions in c
Control statements and functions in cControl statements and functions in c
Control statements and functions in c
 
Behavioral modeling
Behavioral modelingBehavioral modeling
Behavioral modeling
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
 
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
 

Similar to computer programming and utilization

Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
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
Hemantha Kulathilake
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
Chandrakant Divate
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
Tanmay Modi
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
Shipra Swati
 
Session 3
Session 3Session 3
Control statments in c
Control statments in cControl statments in c
Control statments in c
CGC Technical campus,Mohali
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
Anil Dutt
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingPathomchon Sriwilairit
 
NRG 106_Session 4_CLanguage.pptx
NRG 106_Session 4_CLanguage.pptxNRG 106_Session 4_CLanguage.pptx
NRG 106_Session 4_CLanguage.pptx
KRIPABHARDWAJ1
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
Likhil181
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
CIMAP
 
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
Sowmya Jyothi
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
SzeChingChen
 
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
ENGWAU TONNY
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
ganeshkarthy
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
Chandrakant Divate
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
ssuserfb3c3e
 

Similar to computer programming and utilization (20)

Control Structures in C
Control Structures in CControl Structures in C
Control Structures 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
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN CINPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
INPUT AND OUTPUT STATEMENTS IN PROGRAMMING IN C
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8Fundamental of Information Technology - UNIT 8
Fundamental of Information Technology - UNIT 8
 
Session 3
Session 3Session 3
Session 3
 
Control statments in c
Control statments in cControl statments in c
Control statments in c
 
Control statements anil
Control statements anilControl statements anil
Control statements anil
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
NRG 106_Session 4_CLanguage.pptx
NRG 106_Session 4_CLanguage.pptxNRG 106_Session 4_CLanguage.pptx
NRG 106_Session 4_CLanguage.pptx
 
Condition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptxCondition Stmt n Looping stmt.pptx
Condition Stmt n Looping stmt.pptx
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
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
 
Ch6 Loops
Ch6 LoopsCh6 Loops
Ch6 Loops
 
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
 
C_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.pptC_Language_PS&PC_Notes.ppt
C_Language_PS&PC_Notes.ppt
 
Basics of Control Statement in C Languages
Basics of Control Statement in C LanguagesBasics of Control Statement in C Languages
Basics of Control Statement in C Languages
 
Control Structures.pptx
Control Structures.pptxControl Structures.pptx
Control Structures.pptx
 

More from JAYDEV PATEL

SUPERCONDUCTORS
SUPERCONDUCTORSSUPERCONDUCTORS
SUPERCONDUCTORS
JAYDEV PATEL
 
PARALINGUISTICS
PARALINGUISTICSPARALINGUISTICS
PARALINGUISTICS
JAYDEV PATEL
 
LINEAR ALGEBRA AND VECTOR CALCULUS
LINEAR ALGEBRA AND VECTOR CALCULUSLINEAR ALGEBRA AND VECTOR CALCULUS
LINEAR ALGEBRA AND VECTOR CALCULUS
JAYDEV PATEL
 
ELEMENTS OF ELECTRICAL ENGINEERING
ELEMENTS OF ELECTRICAL ENGINEERINGELEMENTS OF ELECTRICAL ENGINEERING
ELEMENTS OF ELECTRICAL ENGINEERING
JAYDEV PATEL
 
Modes of transportation
Modes of transportationModes of transportation
Modes of transportation
JAYDEV PATEL
 
WATER AND WASTE WATER MANAGEMENT
WATER AND WASTE WATER MANAGEMENTWATER AND WASTE WATER MANAGEMENT
WATER AND WASTE WATER MANAGEMENT
JAYDEV PATEL
 
SCALE
SCALESCALE
INTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TEST
INTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TESTINTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TEST
INTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TEST
JAYDEV PATEL
 
Components of pneumatic system
Components of pneumatic systemComponents of pneumatic system
Components of pneumatic system
JAYDEV PATEL
 
Components of hydraulic system
Components of hydraulic systemComponents of hydraulic system
Components of hydraulic system
JAYDEV PATEL
 

More from JAYDEV PATEL (10)

SUPERCONDUCTORS
SUPERCONDUCTORSSUPERCONDUCTORS
SUPERCONDUCTORS
 
PARALINGUISTICS
PARALINGUISTICSPARALINGUISTICS
PARALINGUISTICS
 
LINEAR ALGEBRA AND VECTOR CALCULUS
LINEAR ALGEBRA AND VECTOR CALCULUSLINEAR ALGEBRA AND VECTOR CALCULUS
LINEAR ALGEBRA AND VECTOR CALCULUS
 
ELEMENTS OF ELECTRICAL ENGINEERING
ELEMENTS OF ELECTRICAL ENGINEERINGELEMENTS OF ELECTRICAL ENGINEERING
ELEMENTS OF ELECTRICAL ENGINEERING
 
Modes of transportation
Modes of transportationModes of transportation
Modes of transportation
 
WATER AND WASTE WATER MANAGEMENT
WATER AND WASTE WATER MANAGEMENTWATER AND WASTE WATER MANAGEMENT
WATER AND WASTE WATER MANAGEMENT
 
SCALE
SCALESCALE
SCALE
 
INTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TEST
INTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TESTINTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TEST
INTEGRAL TEST, COMPARISON TEST, RATIO TEST AND ROOT TEST
 
Components of pneumatic system
Components of pneumatic systemComponents of pneumatic system
Components of pneumatic system
 
Components of hydraulic system
Components of hydraulic systemComponents of hydraulic system
Components of hydraulic system
 

Recently uploaded

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
Pipe Restoration Solutions
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 

Recently uploaded (20)

Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
The Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdfThe Benefits and Techniques of Trenchless Pipe Repair.pdf
The Benefits and Techniques of Trenchless Pipe Repair.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 

computer programming and utilization

  • 1. GANDHINAGAR INSTITUTE OF TECHNOLOGY SUBJECT : COMPUTER PROGRAMMING AND UTILIZATION(2110003) TOPIC : “Control Structures in C .” Guided by : Prof. Archana Singh MADE BY:-JAYDEV PATEL(150120119127) KRUNAL PATEL(150120119128) JAIMIN PATEL(150120119126)
  • 2. CONTENT • Introduction • Decision Making Statement i. If else statement ii. Ladder if else iii. Switch statement • Looping i. While loop ii. do-while loop iii. For loop iv. Nesting loop v. Flow breaking statement
  • 3. Introduction • The important and essential part of a programming language is their control structures. 1. Sequence 2. Decision 3. Looping
  • 4. Decision making statement • This is same as choosing one of the alternatives out of the two alternatives available. • There are various types of decision making statements:- i. If else statement ii. Ladder if-else iii. Switch iv. goto
  • 5. If-else statement • The syntax of if else statement is: if(condition) statement 1; else statement 2;
  • 6. Flow chart of if else statement
  • 7. If-else statement • Here the condition is represented by relational or logical expression. • If condition is true, then statement 1 is executed and if condition is false statement 2 is executed. • A compound statement must be enclosedin pair of braces{}. • Enclosing in a single statement is not compulsory. • The else part is is optional. The if statement without else looks like:- if(condition) statement;
  • 8. Write a program to print minimum of two integers. #include<stdio.h> Void main() { Int x,y,min; Printf(“enter two integers”); Scanf(“%d %d”,&x,&y); If(x<y) min=x; Else min=y; Printf(“minimum is:%dn”,min); } • Output:- enter two integers 10 6 Minimum is :6
  • 9. Ladder if-else • The if else is used for two way decision where we select one of the alternative. • But for more than that c supports more multiple if-else or ladder if else for this purpose. • The syntax of multiple if else is:- • If(condition 1) statement1; else if(condition2) statement2; . . else if(conditionN) statementN; else default_statement;
  • 10.
  • 11. Ladder if else • The condition1,condition2,…,conditionN are represented in logical or relational expression s . • if the first condition is true than statement1 will be executed or the other conditions will be evaluated till the correct condition is found. • If the true condition is not found than at last the default statement will be executed.
  • 12. Write a program to compute the electricity bill. #include<stdio.h> Void main() { Int units; Float ucharge,fcharge,gtax,meter_rent= 25.0,total; Printf(“enter number of units consumed”); Scanf(“%d”,units); If(units<=50) Ucharge=0.5*units; Else if(units<=100) Ucharge=50*0.5+(units-50)*0.75; Else if(units<=200) Ucharge=50*0.5+50*0.75+(units-100)*1.00; Else Ucharge=50*0.5+50*0.75+100*1.00+(units-200)*1.50; Fcharge=0.40*ucharge; Gtax=0.10*(ucharge+fcharge); Total=ucharge+fcharge+gtax+meter_rent; Printf(“total bill: %fn”,total); }
  • 13. Output Enter the value of units consumed 85 Total bill : 103.925003
  • 14. Switch statement • The switch in C is a multi-choice statement. • It provides one choice for each value of variable expression. • The syntax of switch is given below: Switch(variable) { Case label1: statement_block1; break; Case label2: statement_block2; break; . . default: default_block
  • 15.
  • 16. Switch statement • Lebel1 ,label2,…. Show the possible value of the variable or expression. • After every statement block there is a break. • Break sends control to the next switch statement. • The last choice is default which is chosen when the value of expression does not match to any of the expression. • But default is optional.
  • 17. Write a program to perform arithmetic operations. #include<stdio.h> #include<conio.h> Void main() { Int choice,a,b; Clrscr(); Printf(“1. add n”); Printf(“2. subn”); Printf(“3. muln”); Printf(“4. divn”); Printf(“Enter your choice:”); Scanf(“%d”,&choice); Printf(“enter two numbers”); Scanf(“%d %d “,&a,&b); Switch(choice) { Case 1: printf(“answer=%dn”,a+b); break; Case 2: printf(“answer=%dn”,a-b); break; Case 3: printf(“answer=%dn”,a*b); break; Case4 : printf(“answer=%dn”a/b); break; Default: break; } }
  • 18. Output 1. Add 2. Sub 3. Mul 4. Div Enter your choice :1 Enter two numbers 23 35 Answer =58
  • 19. Goto statement • The goto statement in C programming is used to transfer the control unconditionally from one part of program to another. • The goto statement can be dangerous to programming languages. • The syntax is Goto label;
  • 20. Write a program to print the sum of 1 to N using goto statement. #include<stdio.h> Void main() { Int i=1,sum=0,n; Printf(“Enter value of N”); Scanf(“%d”,&n); next: Sum= sum+I; i+ =1; If(I <= n ) Goto next; Printf(“sum = %dn”,sum); }
  • 21. Output Enter the value of N 4 Sum = 10
  • 22. Looping • A looping is an important control structure in higher level programming language. • The objective of looping is to provide repetition of the part of the program i.e. block of statements in a program, number of times.
  • 23. Types of loop • There are two types of loop: 1. Entry control 2. Exit control • In entry control loop the condition is checked first and then the body is executed, while in exit control the body is excuted first and then the condition is checked.
  • 24.
  • 25. While loop • The syntax of while loop is: While(condition) { body; }
  • 26.
  • 27. While loop • Here the condition is evaluated first and then the body is executed. After executing the body the condition is evaluated again and if it is true body is executed again. This process is repeated as long as the condition is true. • While loop is a entry control loop. • It is not necessary to enclose body of loop in pair of {} if body contains single statement.
  • 28. Write program to compute the sum of following series. 1²+2²+…+10² #include<stdio.h> Void main() { Int sum=0,n=1; While(n<=10) { sum = = n*n; n++; } Printf(“sum of series :%dn”,sum); }
  • 30. Do-while loop • The syntax of do-while loop is: do{ Body; } while (condition);
  • 31.
  • 32. Do-while loop • In do-while first the body is executed and then the condition is checked. If the condition is true the body is again executed. The body is executed as long as the condition is true. • Do-while loop is a exit control loop. • This ensures the body is atleast once executed even if the condition is false.
  • 33. For loop • The syntax of for loop is : For(<e1>;<e2>;<e3>) { body; }
  • 34.
  • 35. For loop • <e1> is initialization of variable by initial values.<e1> executes only once when we enter in loop. If they are more than one they should be separated by commas. • <e2> is the condition and the if it is true, then the control enters into the body of the loop and executes the statement in body. • After executing the body of the loop, <e3> is executed which modifies the variable.
  • 36. Write a program to print the multiplication table for a given number N. #include<stdio.h> Void main() { Int I,n; Printf(“enter a number”); Scanf(“%d”,&n); Printf(“Table->n”); For(i=1,1<=10;i++) Printf(“%4d*%2d=%4dn’,n,I,n*i); }
  • 38. Nesting of loops • Loop inside loop is called nested loops. For example, … … For( ) { ….. for( ) { ……. …….. } ……. } ……. …….
  • 40. Write a program to print the triangle.for n=5 #include<stdio.h> Void main() { Int n,l,j; Printf(“enter number of lines”); Scanf(“%d”,&n); Printf(“triangle ->n”); For(l=1;l<=n;l++) {for(j=1;j<=1;j++) Printf(“%d”,j); Printf(“n”); } }
  • 41. Output Enter number of lines 5 Triangle-> 1 12 123 1234 12345