SlideShare a Scribd company logo
Lab Report
Course ID: TE-3702
Course Title:-Computer Application and Programming
(Sessional)
Experiment No. 02
Name:-Introduction to C control flow (if, if-else, else if
ladder, nested if, switch ).
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:-
It involves a number of conditions or parameters that determine one of
the various written modules. Structures that use this type of reasoning
are known as conditional structures.it contains 5 decision making
statements:-
1. Simple if statement.
2. if-else statement.
3. else if ladder statement.
4. nested if else statement.
5. Switch statement.
Objectives:-
 To know about simple if statement and its working principle.
 To know about if-else statement and its working principle.
 To know about else if ladder statement and its working principle.
 To know about nested if statement and its working principle.
 To know about switch statement and its working principle.
If statement
When we need to execute a block of statements under a given condition
then we use if statement. The statements inside the body of if only
execute if the given condition is true. If the condition is false then the
statements inside if are skipped that means not show in execute program.
Program
/*Simple if statement program */
#include <stdio.h>
int main()
{int x, y;
printf("the value of x=");
scanf("%d", &x);
printf("the value of y=");
scanf("%d", &y);
if (x>y)
printf("x is larger than yn");
if (x<y)
printf("x is lower than yn");
if (x==y)
printf("x is equal to yn");
return 0;
}
Input:-
Output:-
If else statement:-
When the statements inside the body of if is true under a given condition
then the statements are executed and the statements inside body of else
are skipped.
Again when the statements inside the body of if is false under a given
condition then the statements are skipped and the statements inside body
of else are executed.
Program:-
/*Simple if_else statement program */
#include <stdio.h>
int main()
{
int x,y;
printf("the value of x=");
scanf("%d", &x);
printf("the value of y=");
scanf("%d", &y);
if (x>y)
printf("x is larger than yn");
else
printf("x is lower than yn");
return 0;
}
Input:-
Output:-
else-if ladder statement :-
When we need multiple if conditions for program execution then we use
else if. In this case the statement which is true under the condition is
shown and when any condition is true, then remaining conditions are not
working. In this case the program contains a starting if and ending else
and else if conditions are present between the starting if and ending else.
Program:-
/*else if ladder statement*/
#include <stdio.h>
int main()
{
int marks;
printf("the mark is=");
scanf("%d",&marks);
if(marks>=80)
printf("the result is A+");
else if(marks>=70)
printf("the result is A");
else if(marks>=60)
printf("the result is A-");
else if(marks>=50)
printf("the result is B");
else if(marks>=40)
printf("the result is C");
else
printf("the result is F");
return 0;
}
Input:-
Output:-
nested if else statement:-
Sometimes a program contains starting if condition and in this if
contains again multiple if, else if and else conditions it is known
as nested statement.
Similar occurance is occurred for ending else conditions.
Program:-
/*nested if statement*/
#include<stdio.h>
int main()
{
int num1,num2,num3;
printf("enter the first number=");
scanf("%d", &num1);
printf("enter the second number=");
scanf("%d", &num2);
printf("enter the third number=");
scanf("%d", &num3);
if (num1>num2)
{
if (num2>num3)
printf("the largest number is=%d",num1);
else
printf("the largest number is=%d",num2);
}
if (num1<num2)
{
if (num2<num3)
printf("the largest number is=%d",num3);
else
printf("the largest number is=%d",num2);
}
return 0;
}
Input:-
Output:-
Switch statement:-
Switch statement is used when we choose a specific statement
from multiple statement. When the statement is matched with
the switch condition then the statement is printed and others are
not printed here. If any statement can not match with any case
then the default keyword is used.
There are 4 keywords which are used in the switch statement
and they are switch, break, case and default.
Here the keyword case contains colon sign ( : )
Program :-
#include<stdio.h>
int main()
{
int num;
printf("Enter a number for testing switch=");
scanf("%d", &num);
switch(num)
{
case 0:
printf("zero");
break;
case 1:
printf("one");
break;
case 2:
printf("two");
break;
case 3:
printf("three");
break;
default:
printf("this not valid number for your desirable spelling");
}
return 0;
}
Input:-
Output:-
Conclusion:- From this experiment we have learn about C control
flow which contains some decision making statement and 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 (20)

PPT
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
 
PPT
Lecture 10 - Control Structures 2
Md. Imran Hossain Showrov
 
PPT
Lecture 18 - Pointers
Md. Imran Hossain Showrov
 
PPSX
Bsit1
jigeno
 
PPT
Lecture 8- Data Input and Output
Md. Imran Hossain Showrov
 
PPT
Control Structures
Ghaffar Khan
 
PPTX
Conditional statements
NabishaAK
 
PPTX
Decision statements in c language
tanmaymodi4
 
PPT
If-else and switch-case
Manash Kumar Mondal
 
PPTX
Templates
Farwa Ansari
 
PPTX
Claguage 110226222227-phpapp02
CIMAP
 
PPT
Functions and pointers_unit_4
Saranya saran
 
PPTX
Algoritma pemrograman 5
ZainalAbidin909479
 
PPTX
Conditional Control in MATLAB Scripts
Shameer Ahmed Koya
 
PDF
control statement
Kathmandu University
 
PPT
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
PPT
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
PPTX
Algoritma pemrograman 4
ZainalAbidin909479
 
PPSX
Break and continue statement in C
Innovative
 
Lecture 7- Operators and Expressions
Md. Imran Hossain Showrov
 
Lecture 10 - Control Structures 2
Md. Imran Hossain Showrov
 
Lecture 18 - Pointers
Md. Imran Hossain Showrov
 
Bsit1
jigeno
 
Lecture 8- Data Input and Output
Md. Imran Hossain Showrov
 
Control Structures
Ghaffar Khan
 
Conditional statements
NabishaAK
 
Decision statements in c language
tanmaymodi4
 
If-else and switch-case
Manash Kumar Mondal
 
Templates
Farwa Ansari
 
Claguage 110226222227-phpapp02
CIMAP
 
Functions and pointers_unit_4
Saranya saran
 
Algoritma pemrograman 5
ZainalAbidin909479
 
Conditional Control in MATLAB Scripts
Shameer Ahmed Koya
 
control statement
Kathmandu University
 
Lecture 14 - Scope Rules
Md. Imran Hossain Showrov
 
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
Algoritma pemrograman 4
ZainalAbidin909479
 
Break and continue statement in C
Innovative
 

Similar to 175035 cse lab-03 (20)

PPTX
C Programming: Control Structure
Sokngim Sa
 
PPT
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
PPTX
control_structures_c_language_regarding how to represent the loop in language...
ShirishaBuduputi
 
PDF
Programming Fundamentals Decisions
imtiazalijoono
 
PDF
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
PPTX
Branching statements
ArunMK17
 
PPT
Decisions in C or If condition
yarkhosh
 
PPTX
Control Statements -if else in C programming.pptx
ganeshmahato20
 
PPTX
unit 2-Control Structures.pptx
ishaparte4
 
PDF
Loop's definition and practical code in C programming
DharmaKumariBhandari
 
PPTX
Control structure of c
Komal Kotak
 
PPTX
CONTROL FLOW in C.pptx
SmitaAparadh
 
PPTX
C programming Control Structure.pptx
DEEPAK948083
 
PPTX
Control Structures in C
sana shaikh
 
PDF
C Programming Unit II Sharad Institute college
SatishPise4
 
PPTX
Decision Making and Branching
Munazza-Mah-Jabeen
 
PPT
Introduction to Basic C programming 01
Wingston
 
PDF
7 functions
MomenMostafa
 
PPTX
C decision making and looping.
Haard Shah
 
PPTX
COM1407: Program Control Structures – Decision Making & Branching
Hemantha Kulathilake
 
C Programming: Control Structure
Sokngim Sa
 
CONTROLSTRUCTURES.ppt
Sanjjaayyy
 
control_structures_c_language_regarding how to represent the loop in language...
ShirishaBuduputi
 
Programming Fundamentals Decisions
imtiazalijoono
 
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Branching statements
ArunMK17
 
Decisions in C or If condition
yarkhosh
 
Control Statements -if else in C programming.pptx
ganeshmahato20
 
unit 2-Control Structures.pptx
ishaparte4
 
Loop's definition and practical code in C programming
DharmaKumariBhandari
 
Control structure of c
Komal Kotak
 
CONTROL FLOW in C.pptx
SmitaAparadh
 
C programming Control Structure.pptx
DEEPAK948083
 
Control Structures in C
sana shaikh
 
C Programming Unit II Sharad Institute college
SatishPise4
 
Decision Making and Branching
Munazza-Mah-Jabeen
 
Introduction to Basic C programming 01
Wingston
 
7 functions
MomenMostafa
 
C decision making and looping.
Haard Shah
 
COM1407: Program Control Structures – Decision Making & Branching
Hemantha Kulathilake
 
Ad

More from Mahbubay Rabbani Mim (20)

PDF
Effect of density of the fiber on calculating the properties of textile compo...
Mahbubay Rabbani Mim
 
PPTX
Presentation about Core Spun Yarn.pptx
Mahbubay Rabbani Mim
 
PDF
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Mahbubay Rabbani Mim
 
PDF
Fsd lab 01 study on woven fabric analysis
Mahbubay Rabbani Mim
 
PDF
Water repellent lab report by mim
Mahbubay Rabbani Mim
 
PDF
Presentation on Plain Weave and some Elementary terms of Textilel Design
Mahbubay Rabbani Mim
 
PDF
Wet process lab 02 on Resin Finish treatment for wrinkle free
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 03 asad sir
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 02 asad sir
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 01 asad sir
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 05 asad sir
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 04 asad sir
Mahbubay Rabbani Mim
 
PDF
175035 apparel assignment cutting
Mahbubay Rabbani Mim
 
PDF
175035 spss lab-01
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 01
Mahbubay Rabbani Mim
 
PDF
175035 cse lab-05
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 03
Mahbubay Rabbani Mim
 
DOCX
175035 apparel lab 03
Mahbubay Rabbani Mim
 
PDF
175035 apparel lab 04
Mahbubay Rabbani Mim
 
PDF
175035-cse LAB-04
Mahbubay Rabbani Mim
 
Effect of density of the fiber on calculating the properties of textile compo...
Mahbubay Rabbani Mim
 
Presentation about Core Spun Yarn.pptx
Mahbubay Rabbani Mim
 
Difference among 8085,8086,80186,80286,80386 Microprocessor.pdf
Mahbubay Rabbani Mim
 
Fsd lab 01 study on woven fabric analysis
Mahbubay Rabbani Mim
 
Water repellent lab report by mim
Mahbubay Rabbani Mim
 
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
Mahbubay Rabbani Mim
 
175035 apparel lab 03 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 02 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 01 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 05 asad sir
Mahbubay Rabbani Mim
 
175035 apparel lab 04 asad sir
Mahbubay Rabbani Mim
 
175035 apparel assignment cutting
Mahbubay Rabbani Mim
 
175035 spss lab-01
Mahbubay Rabbani Mim
 
175035 apparel lab 01
Mahbubay Rabbani Mim
 
175035 cse lab-05
Mahbubay Rabbani Mim
 
175035 apparel lab 03
Mahbubay Rabbani Mim
 
175035 apparel lab 03
Mahbubay Rabbani Mim
 
175035 apparel lab 04
Mahbubay Rabbani Mim
 
175035-cse LAB-04
Mahbubay Rabbani Mim
 
Ad

Recently uploaded (20)

PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
ENGLISH 8 WEEK 3 Q1 - Analyzing the linguistic, historical, andor biographica...
OliverOllet
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Digital Professionalism and Interpersonal Competence
rutvikgediya1
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
Cybersecurity: How to Protect your Digital World from Hackers
vaidikpanda4
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 

175035 cse lab-03

  • 1. Lab Report Course ID: TE-3702 Course Title:-Computer Application and Programming (Sessional) Experiment No. 02 Name:-Introduction to C control flow (if, if-else, else if ladder, nested if, switch ). 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:- It involves a number of conditions or parameters that determine one of the various written modules. Structures that use this type of reasoning are known as conditional structures.it contains 5 decision making statements:- 1. Simple if statement. 2. if-else statement. 3. else if ladder statement. 4. nested if else statement. 5. Switch statement. Objectives:-  To know about simple if statement and its working principle.  To know about if-else statement and its working principle.  To know about else if ladder statement and its working principle.  To know about nested if statement and its working principle.  To know about switch statement and its working principle.
  • 3. If statement When we need to execute a block of statements under a given condition then we use if statement. The statements inside the body of if only execute if the given condition is true. If the condition is false then the statements inside if are skipped that means not show in execute program. Program /*Simple if statement program */ #include <stdio.h> int main() {int x, y; printf("the value of x="); scanf("%d", &x); printf("the value of y="); scanf("%d", &y); if (x>y) printf("x is larger than yn"); if (x<y) printf("x is lower than yn"); if (x==y) printf("x is equal to yn"); return 0; }
  • 6. If else statement:- When the statements inside the body of if is true under a given condition then the statements are executed and the statements inside body of else are skipped. Again when the statements inside the body of if is false under a given condition then the statements are skipped and the statements inside body of else are executed. Program:- /*Simple if_else statement program */ #include <stdio.h> int main() { int x,y; printf("the value of x="); scanf("%d", &x); printf("the value of y="); scanf("%d", &y); if (x>y) printf("x is larger than yn"); else printf("x is lower than yn"); return 0; }
  • 9. else-if ladder statement :- When we need multiple if conditions for program execution then we use else if. In this case the statement which is true under the condition is shown and when any condition is true, then remaining conditions are not working. In this case the program contains a starting if and ending else and else if conditions are present between the starting if and ending else. Program:- /*else if ladder statement*/ #include <stdio.h> int main() { int marks; printf("the mark is="); scanf("%d",&marks); if(marks>=80) printf("the result is A+"); else if(marks>=70) printf("the result is A"); else if(marks>=60)
  • 10. printf("the result is A-"); else if(marks>=50) printf("the result is B"); else if(marks>=40) printf("the result is C"); else printf("the result is F"); return 0; }
  • 13. nested if else statement:- Sometimes a program contains starting if condition and in this if contains again multiple if, else if and else conditions it is known as nested statement. Similar occurance is occurred for ending else conditions. Program:- /*nested if statement*/ #include<stdio.h> int main() { int num1,num2,num3; printf("enter the first number="); scanf("%d", &num1); printf("enter the second number="); scanf("%d", &num2); printf("enter the third number="); scanf("%d", &num3); if (num1>num2) { if (num2>num3) printf("the largest number is=%d",num1);
  • 14. else printf("the largest number is=%d",num2); } if (num1<num2) { if (num2<num3) printf("the largest number is=%d",num3); else printf("the largest number is=%d",num2); } return 0; }
  • 17. Switch statement:- Switch statement is used when we choose a specific statement from multiple statement. When the statement is matched with the switch condition then the statement is printed and others are not printed here. If any statement can not match with any case then the default keyword is used. There are 4 keywords which are used in the switch statement and they are switch, break, case and default. Here the keyword case contains colon sign ( : ) Program :- #include<stdio.h> int main() { int num; printf("Enter a number for testing switch="); scanf("%d", &num); switch(num) { case 0: printf("zero"); break;
  • 18. case 1: printf("one"); break; case 2: printf("two"); break; case 3: printf("three"); break; default: printf("this not valid number for your desirable spelling"); } return 0; }
  • 20. Output:- Conclusion:- From this experiment we have learn about C control flow which contains some decision making statement and their working principle which is very important for programming. I think it will help me a lot in practical life.