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

Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions Lecture 7- Operators and Expressions
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
 
Python - Control Structures
Python - Control StructuresPython - Control Structures
Python - Control Structures
LasithNiro
 
Csci101 lect02 selection_andlooping
Csci101 lect02 selection_andloopingCsci101 lect02 selection_andlooping
Csci101 lect02 selection_andlooping
Elsayed Hemayed
 
If statements in c programming
If statements in c programmingIf statements in c programming
If statements in c programming
Archana 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_explanation
srinath v
 
C programming Lab 2
C programming Lab 2C programming Lab 2
C programming Lab 2
Zaibi Gondal
 
175035 cse lab-05
175035 cse lab-05 175035 cse lab-05
175035 cse lab-05
Mahbubay Rabbani Mim
 
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
 
selection structures
selection structuresselection structures
selection structures
Micheal Ogundero
 
composing procedures
composing procedurescomposing procedures
composing procedures
Rajendran
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
Rashmiranja625
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
Zaibi 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 ll
ramivides
 
Chapter 3 branching v4
Chapter 3 branching v4Chapter 3 branching v4
Chapter 3 branching v4
Sunarto Quek
 
Seminar 2 coding_principles
Seminar 2 coding_principlesSeminar 2 coding_principles
Seminar 2 coding_principles
moduledesign
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
Soumen 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
Loops in cLoops in c
Loops in c
shubhampandav3
 
Decision Making and Looping
Decision Making and LoopingDecision Making and Looping
Decision Making and Looping
Munazza-Mah-Jabeen
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
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
Priyom Majumder
 
Slide07 repetitions
Slide07 repetitionsSlide07 repetitions
Slide07 repetitions
altwirqi
 
[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++
Muhammad Hammad Waseem
 
Loop and while Loop
Loop and while LoopLoop and while Loop
Loop and while Loop
JayBhavsar68
 
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
DrDineshenScientist
 
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, Looping
MURALIDHAR R
 
Looping
LoopingLooping
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
sneha2494
 
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
Sowmya Jyothi
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
sana shaikh
 
itretion.docx
itretion.docxitretion.docx
itretion.docx
JavvajiVenkat
 
while loop in C.pptx
while loop in C.pptxwhile loop in C.pptx
while loop in C.pptx
VishnupriyaKashyap
 
Programming basics
Programming basicsProgramming basics
Programming basics
246paa
 

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.pptx
Mahbubay 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.pdf
Mahbubay 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 analysis
Mahbubay Rabbani Mim
 
Water repellent lab report by mim
Water repellent lab report by mimWater repellent lab report by mim
Water repellent lab report by mim
Mahbubay 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 Design
Mahbubay 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 free
Mahbubay Rabbani Mim
 
175035 apparel lab 03 asad sir
175035 apparel lab 03 asad sir175035 apparel lab 03 asad sir
175035 apparel lab 03 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 02 asad sir
175035 apparel lab 02 asad sir175035 apparel lab 02 asad sir
175035 apparel lab 02 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 01 asad sir
175035 apparel lab 01 asad sir175035 apparel lab 01 asad sir
175035 apparel lab 01 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 05 asad sir
175035 apparel lab 05 asad sir175035 apparel lab 05 asad sir
175035 apparel lab 05 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 04 asad sir
175035 apparel lab 04 asad sir175035 apparel lab 04 asad sir
175035 apparel lab 04 asad sir
Mahbubay Rabbani Mim
 
175035 apparel assignment cutting
175035 apparel assignment cutting175035 apparel assignment cutting
175035 apparel assignment cutting
Mahbubay Rabbani Mim
 
175035 spss lab-01
175035 spss lab-01175035 spss lab-01
175035 spss lab-01
Mahbubay Rabbani Mim
 
175035 apparel lab 01
175035 apparel lab 01175035 apparel lab 01
175035 apparel lab 01
Mahbubay Rabbani Mim
 
175035 apparel lab 03
175035 apparel lab 03175035 apparel lab 03
175035 apparel lab 03
Mahbubay Rabbani Mim
 
175035 apparel lab 03
175035 apparel lab 03175035 apparel lab 03
175035 apparel lab 03
Mahbubay Rabbani Mim
 
175035 apparel lab 04
175035 apparel lab 04175035 apparel lab 04
175035 apparel lab 04
Mahbubay Rabbani Mim
 
175035 act lab 04
175035 act lab 04175035 act lab 04
175035 act lab 04
Mahbubay Rabbani Mim
 
175035 apparel lab -02
175035 apparel lab -02175035 apparel lab -02
175035 apparel lab -02
Mahbubay 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

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 

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