SlideShare a Scribd company logo
1 of 22
Download to read offline
Lab Report
Course ID: TE-3702
Course Title:-Computer Application and Programming
(Sessional)
Experiment No. 04
Name:-Introduction to C control flow (for, while, do while,
break and continue).
Submitted by
Name :
ID :
Year and Semester :
Session :
Department :
Mahbubay Rabbani
175035
3/1
2018-19
Textile Engineering
Submitted to
Khawja Imran Masud
Lecturer
Department of CSE
Dhaka University of Engineering & Technology (DUET), Gazipur
Introduction:-
In programming, the process of execution of the same program is over
and over is called looping. A loop is used to repeat a statement until the
specified condition is satisfied. C programming has three types of
loops:-
1. for loop.
2. while loop.
3. do while loop.
Jump Statements in C
 continue.
 break.
 goto.
Objectives:-
 To know about for loop.
 To know about while loop.
 To know about do while loop.
 To know about break statement.
 To know about continue statement.
for loop:-
It works with 3 steps:-
In the 1st
step initialization happens and the variable gets initialized.
In the 2nd
step the condition is checked. If the condition is true then the
C statements inside the body of for loop is executed, if the condition is
false then the for loop gets terminated.
In 3rd
step after successful execution of statements inside the body of
loop, the variable is incremented or decremented and again check the
condition till termination.
Example
#include <stdio.h>
int main()
{
int i;
for (i=1; i<=10; i++)
{
printf("%dn",i);
}
return 0;
}
Output
while loop:-
The variable is initialized with value and then it has been tested for the
condition.
If the condition is true then the statements inside the body of while loop
are executed else the loop is terminated.
The value is incremented using increment ++ operator then it has been
tested again for the loop condition.
Example
#include <stdio.h>
int main()
{
int i=1;
while (i<=10)
{
printf("%dn",i);
i++;
}
}
Output
Infinite while loop:- Inside the body of loop if the condition will be true
always then the loop never terminate.
Example
#include <stdio.h>
int main()
{
int i = 1;
while (i >=1)
{
printf("%d", i);
i++;
}
return 0;
}
Output
do while loop:-
do while loop is similar to while loop but it executes the statements
inside the body of do-while before checking the condition.
On the other hand in the while loop, first the condition is checked and
then the statements are executed.
So if a condition is false at the first place then the do while would
execute once but the while loop would not execute.
Example
#include <stdio.h>
int main()
{
int mim=0;
do
{
printf("mim is=%dn",mim);
mim++;
}while (mim<=3);
return 0;
}
Output
Difference between between while and do while loop:-
Program executed for do while program not executed for while
continue statement:-
The continue statement is used inside loops.
When the condition is true under the continue statement then it skips the
print of statement and again go to the condition check for the next.
Example
#include <stdio.h>
int main()
{
int i;
for(i=0; i<=8; i++)
{
if (i==4)
{
continue;
}
printf("%dn",i);
}
return 0;
}
Output
As here i=4 is true for continue statement and so skip it for
execution that’s why it is not printed.
break statement:-
It is used to terminate the loop instantly.
When the condition is true under the break statement then it terminates
the print of statement.
Example
#include <stdio.h>
int main()
{
int i;
for (i=1;i<=10;i++)
{
printf("%dn",i);
if(i==3)
{
break;
}
}
return 0;
}
Output
As the condition i=3 is true under the break statement and that’s
why not printed up to 10 here and the condition is break after
printed 3
Home task:-
1. Write a proram and display the output
 1+3+5+7+----+n
 2+4+6+8+----+n
Ans:- (Summation of odd numbers)
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("enter the range of numbers=");
scanf("%d",&n);
for(i=1; i<=n; i=i+2)
{
sum=sum+i;
}
printf("the result of all odd numbers=%d",sum);
return 0;
}
Output:-
Ans:- (Summation of even numbers)
#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("enter the range of numbers=");
scanf("%d",&n);
for(i=2; i<=n; i=i+2)
{
sum=sum+i;
}
printf("the result of all even numbers=%d",sum);
return 0;
}
Output:-
2. Write a c program that find the factorial of a number.
Ans:-
#include<stdio.h>
int main()
{
int i,n,f=1;
printf("enter the range of number=");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
f=f*i;
}
printf("the factorial result of the number=%d",f);
return 0;
}
Output:-
Conclusion:- From this experiment we have learn about C control
flow and jump statements and also learn their working principle which is
very important for programming. I think it will help me a lot in practical
life

More Related Content

What's hot

Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control StructuresLasithNiro
 
Csci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingCsci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingElsayed Hemayed
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programmingArchana Gopinath
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7alish sha
 
C language questions_answers_explanation
C language questions_answers_explanationC language questions_answers_explanation
C language questions_answers_explanationsrinath v
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2Zaibi Gondal
 
Dti2143 lab sheet 6
Dti2143 lab sheet 6Dti2143 lab sheet 6
Dti2143 lab sheet 6alish sha
 
computer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressionscomputer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressionsecomputernotes
 
composing procedures
composing procedurescomposing procedures
composing proceduresRajendran
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversionRashmiranja625
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentalsZaibi Gondal
 
Taller número 1 de informática ll
Taller número 1 de informática llTaller número 1 de informática ll
Taller número 1 de informática llramivides
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4Sunarto Quek
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principlesmoduledesign
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackSoumen Santra
 

What's hot (20)

Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
 
07 flow control
07   flow control07   flow control
07 flow control
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
 
Csci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingCsci101 lect02 selection_andlooping
Csci101 lect02 selection_andlooping
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
C language questions_answers_explanation
C language questions_answers_explanationC language questions_answers_explanation
C language questions_answers_explanation
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
 
Dti2143 lab sheet 6
Dti2143 lab sheet 6Dti2143 lab sheet 6
Dti2143 lab sheet 6
 
computer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressionscomputer notes - Evaluating postfix expressions
computer notes - Evaluating postfix expressions
 
selection structures
selection structuresselection structures
selection structures
 
composing procedures
composing procedurescomposing procedures
composing procedures
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
Taller número 1 de informática ll
Taller número 1 de informática llTaller número 1 de informática ll
Taller número 1 de informática ll
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 

Similar to 175035-cse LAB-04

Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopPriyom Majumder
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitionsaltwirqi
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while LoopJayBhavsar68
 
Workbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfWorkbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfDrDineshenScientist
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop kapil078
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, LoopingMURALIDHAR R
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c languagesneha2494
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in CSowmya Jyothi
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
Programming basics
Programming basicsProgramming basics
Programming basics246paa
 

Similar to 175035-cse LAB-04 (20)

Loops in c
Loops in cLoops in c
Loops in c
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested LoopLoops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
 
M C6java6
M C6java6M C6java6
M C6java6
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
 
[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++[ITP - Lecture 11] Loops in C/C++
[ITP - Lecture 11] Loops in C/C++
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
 
Workbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdfWorkbook_2_Problem_Solving_and_programming.pdf
Workbook_2_Problem_Solving_and_programming.pdf
 
12 lec 12 loop
12 lec 12 loop 12 lec 12 loop
12 lec 12 loop
 
C Programming - Decision making, Looping
C  Programming - Decision making, LoopingC  Programming - Decision making, Looping
C Programming - Decision making, Looping
 
Looping
LoopingLooping
Looping
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
 
Unit II chapter 4 Loops in C
Unit II chapter 4 Loops in CUnit II chapter 4 Loops in C
Unit II chapter 4 Loops in C
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
itretion.docx
itretion.docxitretion.docx
itretion.docx
 
Ch3 repetition
Ch3 repetitionCh3 repetition
Ch3 repetition
 
while loop in C.pptx
while loop in C.pptxwhile loop in C.pptx
while loop in C.pptx
 
Bsit1
Bsit1Bsit1
Bsit1
 
Programming basics
Programming basicsProgramming basics
Programming basics
 

More from Mahbubay Rabbani Mim

Effect of density of the fiber on calculating the properties of textile compo...
Effect of density of the fiber on calculating the properties of textile compo...Effect of density of the fiber on calculating the properties of textile compo...
Effect of density of the fiber on calculating the properties of textile compo...Mahbubay Rabbani Mim
 
Presentation about Core Spun Yarn.pptx
Presentation about Core Spun Yarn.pptxPresentation about Core Spun Yarn.pptx
Presentation about Core Spun Yarn.pptxMahbubay Rabbani Mim
 
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdfDifference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdfMahbubay Rabbani Mim
 
Fsd lab 01 study on woven fabric analysis
Fsd lab 01 study on woven fabric analysisFsd lab 01 study on woven fabric analysis
Fsd lab 01 study on woven fabric analysisMahbubay Rabbani Mim
 
Presentation on Plain Weave and some Elementary terms of Textilel Design
Presentation on Plain Weave and some Elementary terms of Textilel DesignPresentation on Plain Weave and some Elementary terms of Textilel Design
Presentation on Plain Weave and some Elementary terms of Textilel DesignMahbubay Rabbani Mim
 
Wet process lab 02 on Resin Finish treatment for wrinkle free
Wet process lab 02 on Resin Finish treatment for wrinkle freeWet process lab 02 on Resin Finish treatment for wrinkle free
Wet process lab 02 on Resin Finish treatment for wrinkle freeMahbubay Rabbani Mim
 

More from Mahbubay Rabbani Mim (20)

Effect of density of the fiber on calculating the properties of textile compo...
Effect of density of the fiber on calculating the properties of textile compo...Effect of density of the fiber on calculating the properties of textile compo...
Effect of density of the fiber on calculating the properties of textile compo...
 
Presentation about Core Spun Yarn.pptx
Presentation about Core Spun Yarn.pptxPresentation about Core Spun Yarn.pptx
Presentation about Core Spun Yarn.pptx
 
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdfDifference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
 
Fsd lab 01 study on woven fabric analysis
Fsd lab 01 study on woven fabric analysisFsd lab 01 study on woven fabric analysis
Fsd lab 01 study on woven fabric analysis
 
Water repellent lab report by mim
Water repellent lab report by mimWater repellent lab report by mim
Water repellent lab report by mim
 
Presentation on Plain Weave and some Elementary terms of Textilel Design
Presentation on Plain Weave and some Elementary terms of Textilel DesignPresentation on Plain Weave and some Elementary terms of Textilel Design
Presentation on Plain Weave and some Elementary terms of Textilel Design
 
Wet process lab 02 on Resin Finish treatment for wrinkle free
Wet process lab 02 on Resin Finish treatment for wrinkle freeWet process lab 02 on Resin Finish treatment for wrinkle free
Wet process lab 02 on Resin Finish treatment for wrinkle free
 
175035 apparel lab 03 asad sir
175035 apparel lab 03 asad sir175035 apparel lab 03 asad sir
175035 apparel lab 03 asad sir
 
175035 apparel lab 02 asad sir
175035 apparel lab 02 asad sir175035 apparel lab 02 asad sir
175035 apparel lab 02 asad sir
 
175035 apparel lab 01 asad sir
175035 apparel lab 01 asad sir175035 apparel lab 01 asad sir
175035 apparel lab 01 asad sir
 
175035 apparel lab 05 asad sir
175035 apparel lab 05 asad sir175035 apparel lab 05 asad sir
175035 apparel lab 05 asad sir
 
175035 apparel lab 04 asad sir
175035 apparel lab 04 asad sir175035 apparel lab 04 asad sir
175035 apparel lab 04 asad sir
 
175035 apparel assignment cutting
175035 apparel assignment cutting175035 apparel assignment cutting
175035 apparel assignment cutting
 
175035 spss lab-01
175035 spss lab-01175035 spss lab-01
175035 spss lab-01
 
175035 apparel lab 01
175035 apparel lab 01175035 apparel lab 01
175035 apparel lab 01
 
175035 apparel lab 03
175035 apparel lab 03175035 apparel lab 03
175035 apparel lab 03
 
175035 apparel lab 03
175035 apparel lab 03175035 apparel lab 03
175035 apparel lab 03
 
175035 apparel lab 04
175035 apparel lab 04175035 apparel lab 04
175035 apparel lab 04
 
175035 act lab 04
175035 act lab 04175035 act lab 04
175035 act lab 04
 
175035 apparel lab -02
175035 apparel lab -02175035 apparel lab -02
175035 apparel lab -02
 

Recently uploaded

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 

Recently uploaded (20)

Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 

175035-cse LAB-04

  • 1. Lab Report Course ID: TE-3702 Course Title:-Computer Application and Programming (Sessional) Experiment No. 04 Name:-Introduction to C control flow (for, while, do while, break and continue). Submitted by Name : ID : Year and Semester : Session : Department : Mahbubay Rabbani 175035 3/1 2018-19 Textile Engineering Submitted to Khawja Imran Masud Lecturer Department of CSE Dhaka University of Engineering & Technology (DUET), Gazipur
  • 2. Introduction:- In programming, the process of execution of the same program is over and over is called looping. A loop is used to repeat a statement until the specified condition is satisfied. C programming has three types of loops:- 1. for loop. 2. while loop. 3. do while loop. Jump Statements in C  continue.  break.  goto. Objectives:-  To know about for loop.  To know about while loop.  To know about do while loop.  To know about break statement.  To know about continue statement.
  • 3. for loop:- It works with 3 steps:- In the 1st step initialization happens and the variable gets initialized. In the 2nd step the condition is checked. If the condition is true then the C statements inside the body of for loop is executed, if the condition is false then the for loop gets terminated. In 3rd step after successful execution of statements inside the body of loop, the variable is incremented or decremented and again check the condition till termination.
  • 4. Example #include <stdio.h> int main() { int i; for (i=1; i<=10; i++) { printf("%dn",i); } return 0; } Output
  • 5. while loop:- The variable is initialized with value and then it has been tested for the condition. If the condition is true then the statements inside the body of while loop are executed else the loop is terminated. The value is incremented using increment ++ operator then it has been tested again for the loop condition. Example #include <stdio.h> int main() { int i=1; while (i<=10) { printf("%dn",i); i++; } }
  • 7. Infinite while loop:- Inside the body of loop if the condition will be true always then the loop never terminate. Example #include <stdio.h> int main() { int i = 1; while (i >=1) { printf("%d", i); i++; } return 0; }
  • 9. do while loop:- do while loop is similar to while loop but it executes the statements inside the body of do-while before checking the condition. On the other hand in the while loop, first the condition is checked and then the statements are executed. So if a condition is false at the first place then the do while would execute once but the while loop would not execute. Example #include <stdio.h> int main() { int mim=0; do { printf("mim is=%dn",mim); mim++; }while (mim<=3); return 0; }
  • 11. Difference between between while and do while loop:- Program executed for do while program not executed for while
  • 12. continue statement:- The continue statement is used inside loops. When the condition is true under the continue statement then it skips the print of statement and again go to the condition check for the next. Example #include <stdio.h> int main() { int i; for(i=0; i<=8; i++) { if (i==4) { continue; } printf("%dn",i); } return 0; }
  • 13. Output As here i=4 is true for continue statement and so skip it for execution that’s why it is not printed.
  • 14. break statement:- It is used to terminate the loop instantly. When the condition is true under the break statement then it terminates the print of statement. Example #include <stdio.h> int main() { int i; for (i=1;i<=10;i++) { printf("%dn",i); if(i==3) { break; } } return 0; }
  • 15. Output As the condition i=3 is true under the break statement and that’s why not printed up to 10 here and the condition is break after printed 3
  • 16. Home task:- 1. Write a proram and display the output  1+3+5+7+----+n  2+4+6+8+----+n Ans:- (Summation of odd numbers) #include<stdio.h> int main() { int i,n,sum=0; printf("enter the range of numbers="); scanf("%d",&n); for(i=1; i<=n; i=i+2) { sum=sum+i; } printf("the result of all odd numbers=%d",sum); return 0; }
  • 18. Ans:- (Summation of even numbers) #include<stdio.h> int main() { int i,n,sum=0; printf("enter the range of numbers="); scanf("%d",&n); for(i=2; i<=n; i=i+2) { sum=sum+i; } printf("the result of all even numbers=%d",sum); return 0; }
  • 20. 2. Write a c program that find the factorial of a number. Ans:- #include<stdio.h> int main() { int i,n,f=1; printf("enter the range of number="); scanf("%d",&n); for(i=1; i<=n; i++) { f=f*i; } printf("the factorial result of the number=%d",f); return 0; }
  • 22. Conclusion:- From this experiment we have learn about C control flow and jump statements and also learn their working principle which is very important for programming. I think it will help me a lot in practical life