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;
computer programming and utilization
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
computer programming and utilization
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.
computer programming and utilization
While loop
• The syntax of while loop is:
While(condition)
{
body;
}
computer programming and utilization
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);
computer programming and utilization
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;
}
computer programming and utilization
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 (20)

Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Control Structures
Control StructuresControl Structures
Control Structures
Ghaffar 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 structures in c
Control structures in cControl structures in c
Control structures in c
baabtra.com - No. 1 supplier of quality freshers
 
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 statement in c
Control statement in cControl statement in c
Control statement in c
baabtra.com - No. 1 supplier of quality freshers
 
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
 
Control statement-Selective
Control statement-SelectiveControl statement-Selective
Control statement-Selective
Nurul Zakiah Zamri Tan
 
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
 

Similar to computer programming and utilization (20)

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
 
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdfPROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
JNTUK KAKINADA
 
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
Dr. Chandrakant Divate
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
Tanmay Modi
 
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
Session 3
Shailendra Mathur
 
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 Programming
Pathomchon 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
 
TN 12 computer Science - ppt CHAPTER-6.pptx
TN 12 computer Science - ppt CHAPTER-6.pptxTN 12 computer Science - ppt CHAPTER-6.pptx
TN 12 computer Science - ppt CHAPTER-6.pptx
knmschool
 
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
 
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
 
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdfPROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
PROBLEM SOLVING USING NOW PPSC- UNIT -2.pdf
JNTUK KAKINADA
 
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
Dr. Chandrakant Divate
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
Tanmay Modi
 
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
 
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 Programming
Pathomchon 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
 
TN 12 computer Science - ppt CHAPTER-6.pptx
TN 12 computer Science - ppt CHAPTER-6.pptxTN 12 computer Science - ppt CHAPTER-6.pptx
TN 12 computer Science - ppt CHAPTER-6.pptx
knmschool
 
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
 
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
 
Ad

More from JAYDEV PATEL (10)

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
SCALE
JAYDEV PATEL
 
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
 
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
 
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
 
Ad

Recently uploaded (20)

Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
[HIFLUX] Lok Fitting&Valve Catalog 2025 (Eng)
하이플럭스 / HIFLUX Co., Ltd.
 
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdfISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
Application Security and Secure Software Development Lifecycle
Application  Security and Secure Software Development LifecycleApplication  Security and Secure Software Development Lifecycle
Application Security and Secure Software Development Lifecycle
DrKavithaP1
 
UNIT-5-PPT Computer Control Power of Power System
UNIT-5-PPT Computer Control Power of Power SystemUNIT-5-PPT Computer Control Power of Power System
UNIT-5-PPT Computer Control Power of Power System
Sridhar191373
 
UNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and ControlUNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and Control
Sridhar191373
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
Android basics – Key Codes – ADB – Rooting Android – Boot Process – File Syst...
ManiMaran230751
 
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
Forensic Science – Digital Forensics – Digital Evidence – The Digital Forensi...
ManiMaran230751
 
Software Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance OptimizationSoftware Developer Portfolio: Backend Architecture & Performance Optimization
Software Developer Portfolio: Backend Architecture & Performance Optimization
kiwoong (daniel) kim
 
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdfSoftware_Engineering_in_6_Hours_lyst1728638742594.pdf
Software_Engineering_in_6_Hours_lyst1728638742594.pdf
VanshMunjal7
 
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
9aeb2aae-3b85-47a5-9776-154883bbae57.pdf
RishabhGupta578788
 
Influence line diagram for truss in a robust
Influence line diagram for truss in a robustInfluence line diagram for truss in a robust
Influence line diagram for truss in a robust
ParthaSengupta26
 
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
May 2025 - Top 10 Read Articles in Artificial Intelligence and Applications (...
gerogepatton
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
Application Security and Secure Software Development Lifecycle
Application  Security and Secure Software Development LifecycleApplication  Security and Secure Software Development Lifecycle
Application Security and Secure Software Development Lifecycle
DrKavithaP1
 
UNIT-5-PPT Computer Control Power of Power System
UNIT-5-PPT Computer Control Power of Power SystemUNIT-5-PPT Computer Control Power of Power System
UNIT-5-PPT Computer Control Power of Power System
Sridhar191373
 
UNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and ControlUNIT-1-PPT-Introduction about Power System Operation and Control
UNIT-1-PPT-Introduction about Power System Operation and Control
Sridhar191373
 
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra OpticaPruebas y Solucion de problemas empresariales en redes de Fibra Optica
Pruebas y Solucion de problemas empresariales en redes de Fibra Optica
OmarAlfredoDelCastil
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
Fresh concrete Workability Measurement
Fresh concrete  Workability  MeasurementFresh concrete  Workability  Measurement
Fresh concrete Workability Measurement
SasiVarman5
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.pptfy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
fy06_46f6-ht30_22_oil_gas_industry_guidelines.ppt
sukarnoamin
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 

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;
  • 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
  • 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.
  • 25. While loop • The syntax of while loop is: While(condition) { body; }
  • 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);
  • 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; }
  • 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