SlideShare a Scribd company logo
1 of 21
Download to read offline
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 1
Handout#4
Assignment/Program Statement:
Write C programs using decision control statements such as if, if-else, else_if
ladder and nested if-else.
Learning Objectives:
Students will be able to
- explain decision control statements in C
- write C code using if statement in C
- write C code using if_else statement in C
- write C code using else_if ladder in C
- write C code using nested if-else in C
- draw flowchart for decision making solutions
Theory:
A decision control instruction can be implemented in C using following decision
control constructs:
1) The if statement
2) The if - else statement
3) Ladder else_if (or switch-case statement)
4) Nested if_else
4-a) Write a C program using if statement.
4-b) Write a C program using if_else statement.
4-c) Write a C program using else_if ladder.
4-d) Write a C program using nested if-else.
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 2
Assignment#4a
Program Statement:
Write a C program using if statement - to display message if given number is
greater than 10 using if statement.
Learning Objectives:
Students will be able to
- explain decision control statements in C
- write C code using if statement in C
- draw flowchart for decision making solutions
Theory:
The if statement:
 The code inside “if” body executes only when the condition defined by the
“if” statement is “true”.
 If the condition is “false” then compiler skips the statement enclosed in if‟s
body.
 We can have any number of if statements in a C program.
The general form of if statement looks like this:
if (this condition is true)
{
execute this statement;
}
Example:
C code to check given number in „n‟ variable is smaller than 10.
if (n<10)
{
printf(“n N is smaller than 10”);
}
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 3
Flow-Diagram for if statement:
Algorithm:
Step1: Start
Step2: Read value of n from user
Step3: If „N‟ > 10 then
print “N is greater than 10
End If
Step4: Stop
Flowchart:
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 4
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“n Enter number (N):”);
scanf(“%d”, &n);
if(n>10){
printf(“n %d is greater than 10”);
}
}
Input:
Enter number (N): 5
Output:
5 is greater than 10
Practice Problem Statements:
Write a program using if statement
i) To calculate area of circle if given radius value is not equal to zero.
ii) To display message if given two numbers addition is equal to 35.
Conclusion:
Thus C program using if statement - to display message if given number is greater
than 10 using if statement is implemented
Assignment Outcome:
At the end of this assignment, students are be able to
- explain decision control statements in C
- write C code using if statement in C
- draw flowchart for decision making solutions
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 5
Assignment#4b
Program Statement:
Write a C program using if-else statement, to display greater number amongst
given two numbers a & b.
Learning Objectives:
Students will be able to
- explain decision control statements in C
- write C code using if-else statement in C
- draw flowchart for decision making solutions
Theory:
The if_else statement:
 If we have two blocks of statements then we use if_else statement.
 If the condition results “true” then “if” block gets in execution otherwise
statements in “else” block executes.
 The “else” cannot exist without if statement.
 If the condition is “true”, it executes one set of statements and if the
condition is “false”, it executes another set of instructions.
The general form of if_else statement
if(condition)
{
statements;
}
else
{
statements;
}
Example:
C code to check greater number amongst a & b.
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 6
if (a>b)
{
printf(“n a is greater”);
}
else
{
printf(“n b is greater”);
}
Flow-Diagram for if-else statement:
Algorithm:
Step1: Start
Step2: Read value of A and B from user
Step3: If A > B then
Print “A is greater number”
goto step4
Else
Print “B is greater number”
Gtoto step4
End If
Step4: Stop
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 7
Flowchart:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b;
clrscr();
printf(“n Enter value of „A‟:”);
scanf(“%d”, &a);
printf(“n Enter value of „B‟:”);
scanf(“%d”, &b);
if(a>b)
{
printf(“n %d is greater number”,a);
}
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 8
else
{
printf(“n %d is greater number”,b);
}
}
Input:
Enter value of „A‟: 25
Enter value of „B‟: 50
Output:
50 is greater number
Practice Problem Statements:
Write a program using if_else statement
i) To read person‟s age and decide whether that person is eligible for voting
or not and accordingly display messages.
ii) To check that user entered number is positive or negative and
accordingly display messages.
iii) To decide given number is EVEN or ODD.
Conclusion:
Thus a C program using if-else statement, to display greater number amongst given
two numbers a & b is implemented.
Learning Outcome:
At the end of this assignment, students are able to
- explain decision control statements in C
- write C code using if-else statement in C
- draw flowchart for decision making solutions
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 9
Assignment#4c
Program Statement:
Write a C program using else-if ladder statement, to display grades accordingly
marks.
(For example if marks obtained is less than 40 then fail, if marks is in between 40
to 59 then C grade, if marks is in between 60 to 74 then B grade, if marks is in
between 75 to 90 then A grade and marks in between 90 to 10 then A+ grade
otherwise invalid marks.
Learning Objectives:
Students will be able to
- explain decision control statements in C
- write C code using else-if ladder in C
- draw flowchart for decision making solutions
Theory:
Ladder else_if statements:
 If we are having different - different test conditions with different - different
statements, then for these kind of programming we need else if leader.
The general form of else_if statements
if(test_condition1)
{
statement 1;
}
else if(test_condition2)
{
statement 2;
}
else if(test_condition3)
{
statement 3;
}
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 10
else // at last, we use only else.
{
statement x;
}
In above syntax there are four test conditions with four different - different
statements.
Example:
C code to check greater number amongst three numbers a, b & c.
if (a>b && a>c)
{
printf(“n %d is greater number” ,a);
}
else if(b>a && b>c)
{
printf(“n %d is greater number”, b);
}
else
{
printf(“n %d is greater number”,c);
}
Flow-Diagram for if-else statement:
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 11
Algorithm:
Step1: Start
Step2: Read „marks‟
Step3: If marks<40 Then
Print “Fail”
goto step4
Else If marks >=40 and marks<60 Then
Print “Grade-C”
goto step4
Else If marks>=60 and marks<75 Then
Print “Grade-B”
goto step4
Else If marks>=75 and marks<90 Then
Print “Grade-A”
goto step4
Else If marks>=90 Then
Print “Grade-A+”
goto step4
Else
Print “Invalid”
End If
Step4: Stop
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 12
Flowchart:
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 13
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int marks;
clrscr();
printf(“n Enter marks:”);
scanf(“%d”, &marks);
if (marks<40)
{
printf(“n Fail”);
}
else if(marks>=40 && marks<60)
{
printf(“n Grade-C”);
}
else if(marks >=60 && marks <75)
{
printf(“n Grade-B”);
}
else if(marks>=75 && marks<90)
{
printf(“n Grade-A”);
}
else if(marks>90)
{
printf(“n Grade-A+”);
}
else
{
printf(“n Invalid”);
}
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 14
getch();
}
Input:
Enter marks: 65
Output:
Grade-B
Practice Problem Statements:
1) Write a program to enter the temperature and print the following message
according to the given temperature by using else_if ladder statement.
1. T<=0 "Its very very cold".
2. 0 < T < 0 "Its cold".
3. 10 < T < =20 "Its cool out".
4. 20 < T < =30 "Its warm".
5. T>30 "Its hot".
2) Write a program to perform arithmetic operation based on user choice. First read
two integer numbers from user and operator symbol e.g. +, -, *, / and %. Based on
user choice perform arithmetic operation and display result. Here use ladder else_if
construct.
Input:
Enter two numbers: 12 13
Enter operation: +
Output:
Addition of two numbers 12 & 13 is equal to 25
Conclusion:
Thus a C program using else-if ladder statement, to display grades accordingly
marks is implemented
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 15
Learning Outcomes:
At the end of this assignment, students are able to
- explain decision control statements in C
- write C code using else-if ladder in C
- draw flowchart for decision making solutions
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 16
Assignment#4d
Program Statement:
Write a C program using nested if_else statement, to display greater number
amongst given three numbers a, b, & c grades accordingly marks.
Learning Objectives:
Students will be able to
- explain decision control statements in C
- write C code using else-if ladder in C
- draw flowchart for decision making solutions
Theory:
Nested if_else construct:
 In Nested if ..... else, the if and else part can contain one or more if else
statements.
General Form:
if(conditional-expression)
{
if(conditional-expression)
{
statements;
}
else
{
statements;
}
statements;
}
else
{
if(conditional-expression)
{
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 17
statements;
}
statements;
}
Example:
C code to check greater number amongst three given numbers a, b & c.
if (a>b)
{
if(a>c)
{
printf(“%d is greater number”,a);
}
else
{
printf(“%d is greater number”,c);
}
}
else
{
if(b>c)
{
printf(“%d is greater number”,b);
}
else
{
printf(“%d is greater number”,c);
}
}
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 18
Flow-Diagram for if-else statement:
Algorithm:
Step1: Start
Step2: Read two numbers A & B
Step3: If A > B Then
If A > C Then
Print “A is greater number”
Else
Print “C is greater number”
End If
Else
If B> C Then
Print “B is greater number”
Else
Print “C is greater number”
End If
End If
Step4: Stop
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 19
Flowchart:
Program:
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf(“n Enter three numbers:”);
scanf(“%d %d %d”, &a, &b, &c);
if (a>b)
{
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 20
if(a>c)
{
printf(“n %d is greater number.”,a);
}
else
{
printf(“n %d is greater number.”,c);
}
}
else
{
if(b>c)
{
printf(“n %d is greater number.”,a);
}
else
{
printf(“n %d is greater number.”,c);
}
}
}
Input:
Enter three numbers: 10 30 20
Output:
30 is greater number.
Practice Problem Statements:
Write a C program to decide given number is divisible by 3 and 2 or 4 and 2
using nested if_else statement.
C-Programming
Walchand Institute of Technology (RC1131), Solapur Page 21
Conclusion:
Thus a C program using nested if_else statement, to display greater number
amongst given three numbers a, b, & c grades accordingly marks is implemented.
Learning Outcomes:
At the end of this assignment, students are able to
- explain decision control statements in C
- write C code using else-if ladder in C
- draw flowchart for decision making solutions

More Related Content

What's hot

What's hot (20)

Functions in c++
Functions in c++Functions in c++
Functions in c++
 
Recursive Function
Recursive FunctionRecursive Function
Recursive Function
 
Introduction to C++
Introduction to C++ Introduction to C++
Introduction to C++
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 
Programming in C Presentation upto FILE
Programming in C Presentation upto FILEProgramming in C Presentation upto FILE
Programming in C Presentation upto FILE
 
Polymorphism in Java
Polymorphism in JavaPolymorphism in Java
Polymorphism in Java
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
 
Lecture 1- History of C Programming
Lecture 1- History of C Programming Lecture 1- History of C Programming
Lecture 1- History of C Programming
 
C# Loops
C# LoopsC# Loops
C# Loops
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
Function in c
Function in cFunction in c
Function in c
 
NFA Non Deterministic Finite Automata by Mudasir khushik
NFA Non Deterministic Finite Automata by Mudasir khushikNFA Non Deterministic Finite Automata by Mudasir khushik
NFA Non Deterministic Finite Automata by Mudasir khushik
 
Control structures in C
Control structures in CControl structures in C
Control structures in C
 
Python vs c++ ppt
Python vs c++ pptPython vs c++ ppt
Python vs c++ ppt
 
Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder Nesting of if else statement & Else If Ladder
Nesting of if else statement & Else If Ladder
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
If else statement in c++
If else statement in c++If else statement in c++
If else statement in c++
 

Similar to C-Programming Decision Control Statements

C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.Haard Shah
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in Csana shaikh
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfjanakim15
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdSyed Mustafa
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CSyed Mustafa
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newLast7693
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newscottbrownnn
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab neweyavagal
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notesSrikanth
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfmadihamaqbool6
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingHemantha Kulathilake
 
cuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfcuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfYashwanthCse
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solutionKuntal Bhowmick
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 

Similar to C-Programming Decision Control Statements (20)

C decision making and looping.
C decision making and looping.C decision making and looping.
C decision making and looping.
 
Looping statements
Looping statementsLooping statements
Looping statements
 
c programing
c programingc programing
c programing
 
Control Structures in C
Control Structures in CControl Structures in C
Control Structures in C
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
C and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdfC and Data structure lab manual ECE (2).pdf
C and Data structure lab manual ECE (2).pdf
 
Elements of programming
Elements of programmingElements of programming
Elements of programming
 
answer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcdanswer-model-qp-15-pcd13pcd
answer-model-qp-15-pcd13pcd
 
VTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in CVTU PCD Model Question Paper - Programming in C
VTU PCD Model Question Paper - Programming in C
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Md university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab newMd university cmis 102 week 4 hands on lab new
Md university cmis 102 week 4 hands on lab new
 
Datastructure notes
Datastructure notesDatastructure notes
Datastructure notes
 
C programming
C programmingC programming
C programming
 
UoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdfUoN-Lec_12_Control_Structure.pdf
UoN-Lec_12_Control_Structure.pdf
 
ICP - Lecture 7 and 8
ICP - Lecture 7 and 8ICP - Lecture 7 and 8
ICP - Lecture 7 and 8
 
COM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & BranchingCOM1407: Program Control Structures – Decision Making & Branching
COM1407: Program Control Structures – Decision Making & Branching
 
cuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdfcuptopointer-180804092048-190306091149 (2).pdf
cuptopointer-180804092048-190306091149 (2).pdf
 
Cs291 assignment solution
Cs291 assignment solutionCs291 assignment solution
Cs291 assignment solution
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 

More from trupti1976

MobileAppDev Handout#3
MobileAppDev Handout#3MobileAppDev Handout#3
MobileAppDev Handout#3trupti1976
 
MobileAppDev Handout#10
MobileAppDev Handout#10MobileAppDev Handout#10
MobileAppDev Handout#10trupti1976
 
MobileAppDev Handout#9
MobileAppDev Handout#9MobileAppDev Handout#9
MobileAppDev Handout#9trupti1976
 
MobileAppDev Handout#8
MobileAppDev Handout#8MobileAppDev Handout#8
MobileAppDev Handout#8trupti1976
 
MobileAppDev Handout#7
MobileAppDev Handout#7MobileAppDev Handout#7
MobileAppDev Handout#7trupti1976
 
MobileAppDev Handout#6
MobileAppDev Handout#6MobileAppDev Handout#6
MobileAppDev Handout#6trupti1976
 
MobileAppDev Handout#5
MobileAppDev Handout#5MobileAppDev Handout#5
MobileAppDev Handout#5trupti1976
 
MobileAppDev Handout#4
MobileAppDev Handout#4MobileAppDev Handout#4
MobileAppDev Handout#4trupti1976
 
MobileAppDev Handout#2
MobileAppDev Handout#2MobileAppDev Handout#2
MobileAppDev Handout#2trupti1976
 
MobileAppDev Handout#1
MobileAppDev Handout#1MobileAppDev Handout#1
MobileAppDev Handout#1trupti1976
 

More from trupti1976 (18)

MobileAppDev Handout#3
MobileAppDev Handout#3MobileAppDev Handout#3
MobileAppDev Handout#3
 
MobileAppDev Handout#10
MobileAppDev Handout#10MobileAppDev Handout#10
MobileAppDev Handout#10
 
MobileAppDev Handout#9
MobileAppDev Handout#9MobileAppDev Handout#9
MobileAppDev Handout#9
 
MobileAppDev Handout#8
MobileAppDev Handout#8MobileAppDev Handout#8
MobileAppDev Handout#8
 
MobileAppDev Handout#7
MobileAppDev Handout#7MobileAppDev Handout#7
MobileAppDev Handout#7
 
MobileAppDev Handout#6
MobileAppDev Handout#6MobileAppDev Handout#6
MobileAppDev Handout#6
 
MobileAppDev Handout#5
MobileAppDev Handout#5MobileAppDev Handout#5
MobileAppDev Handout#5
 
MobileAppDev Handout#4
MobileAppDev Handout#4MobileAppDev Handout#4
MobileAppDev Handout#4
 
MobileAppDev Handout#2
MobileAppDev Handout#2MobileAppDev Handout#2
MobileAppDev Handout#2
 
MobileAppDev Handout#1
MobileAppDev Handout#1MobileAppDev Handout#1
MobileAppDev Handout#1
 
CP Handout#10
CP Handout#10CP Handout#10
CP Handout#10
 
CP Handout#9
CP Handout#9CP Handout#9
CP Handout#9
 
CP Handout#8
CP Handout#8CP Handout#8
CP Handout#8
 
CP Handout#7
CP Handout#7CP Handout#7
CP Handout#7
 
CP Handout#6
CP Handout#6CP Handout#6
CP Handout#6
 
CP Handout#3
CP Handout#3CP Handout#3
CP Handout#3
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
CP Handout#1
CP Handout#1CP Handout#1
CP Handout#1
 

Recently uploaded

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 

Recently uploaded (20)

CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 

C-Programming Decision Control Statements

  • 1. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 1 Handout#4 Assignment/Program Statement: Write C programs using decision control statements such as if, if-else, else_if ladder and nested if-else. Learning Objectives: Students will be able to - explain decision control statements in C - write C code using if statement in C - write C code using if_else statement in C - write C code using else_if ladder in C - write C code using nested if-else in C - draw flowchart for decision making solutions Theory: A decision control instruction can be implemented in C using following decision control constructs: 1) The if statement 2) The if - else statement 3) Ladder else_if (or switch-case statement) 4) Nested if_else 4-a) Write a C program using if statement. 4-b) Write a C program using if_else statement. 4-c) Write a C program using else_if ladder. 4-d) Write a C program using nested if-else.
  • 2. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 2 Assignment#4a Program Statement: Write a C program using if statement - to display message if given number is greater than 10 using if statement. Learning Objectives: Students will be able to - explain decision control statements in C - write C code using if statement in C - draw flowchart for decision making solutions Theory: The if statement:  The code inside “if” body executes only when the condition defined by the “if” statement is “true”.  If the condition is “false” then compiler skips the statement enclosed in if‟s body.  We can have any number of if statements in a C program. The general form of if statement looks like this: if (this condition is true) { execute this statement; } Example: C code to check given number in „n‟ variable is smaller than 10. if (n<10) { printf(“n N is smaller than 10”); }
  • 3. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 3 Flow-Diagram for if statement: Algorithm: Step1: Start Step2: Read value of n from user Step3: If „N‟ > 10 then print “N is greater than 10 End If Step4: Stop Flowchart:
  • 4. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 4 Program: #include<stdio.h> #include<conio.h> void main() { int n; clrscr(); printf(“n Enter number (N):”); scanf(“%d”, &n); if(n>10){ printf(“n %d is greater than 10”); } } Input: Enter number (N): 5 Output: 5 is greater than 10 Practice Problem Statements: Write a program using if statement i) To calculate area of circle if given radius value is not equal to zero. ii) To display message if given two numbers addition is equal to 35. Conclusion: Thus C program using if statement - to display message if given number is greater than 10 using if statement is implemented Assignment Outcome: At the end of this assignment, students are be able to - explain decision control statements in C - write C code using if statement in C - draw flowchart for decision making solutions
  • 5. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 5 Assignment#4b Program Statement: Write a C program using if-else statement, to display greater number amongst given two numbers a & b. Learning Objectives: Students will be able to - explain decision control statements in C - write C code using if-else statement in C - draw flowchart for decision making solutions Theory: The if_else statement:  If we have two blocks of statements then we use if_else statement.  If the condition results “true” then “if” block gets in execution otherwise statements in “else” block executes.  The “else” cannot exist without if statement.  If the condition is “true”, it executes one set of statements and if the condition is “false”, it executes another set of instructions. The general form of if_else statement if(condition) { statements; } else { statements; } Example: C code to check greater number amongst a & b.
  • 6. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 6 if (a>b) { printf(“n a is greater”); } else { printf(“n b is greater”); } Flow-Diagram for if-else statement: Algorithm: Step1: Start Step2: Read value of A and B from user Step3: If A > B then Print “A is greater number” goto step4 Else Print “B is greater number” Gtoto step4 End If Step4: Stop
  • 7. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 7 Flowchart: Program: #include<stdio.h> #include<conio.h> void main() { int a, b; clrscr(); printf(“n Enter value of „A‟:”); scanf(“%d”, &a); printf(“n Enter value of „B‟:”); scanf(“%d”, &b); if(a>b) { printf(“n %d is greater number”,a); }
  • 8. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 8 else { printf(“n %d is greater number”,b); } } Input: Enter value of „A‟: 25 Enter value of „B‟: 50 Output: 50 is greater number Practice Problem Statements: Write a program using if_else statement i) To read person‟s age and decide whether that person is eligible for voting or not and accordingly display messages. ii) To check that user entered number is positive or negative and accordingly display messages. iii) To decide given number is EVEN or ODD. Conclusion: Thus a C program using if-else statement, to display greater number amongst given two numbers a & b is implemented. Learning Outcome: At the end of this assignment, students are able to - explain decision control statements in C - write C code using if-else statement in C - draw flowchart for decision making solutions
  • 9. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 9 Assignment#4c Program Statement: Write a C program using else-if ladder statement, to display grades accordingly marks. (For example if marks obtained is less than 40 then fail, if marks is in between 40 to 59 then C grade, if marks is in between 60 to 74 then B grade, if marks is in between 75 to 90 then A grade and marks in between 90 to 10 then A+ grade otherwise invalid marks. Learning Objectives: Students will be able to - explain decision control statements in C - write C code using else-if ladder in C - draw flowchart for decision making solutions Theory: Ladder else_if statements:  If we are having different - different test conditions with different - different statements, then for these kind of programming we need else if leader. The general form of else_if statements if(test_condition1) { statement 1; } else if(test_condition2) { statement 2; } else if(test_condition3) { statement 3; }
  • 10. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 10 else // at last, we use only else. { statement x; } In above syntax there are four test conditions with four different - different statements. Example: C code to check greater number amongst three numbers a, b & c. if (a>b && a>c) { printf(“n %d is greater number” ,a); } else if(b>a && b>c) { printf(“n %d is greater number”, b); } else { printf(“n %d is greater number”,c); } Flow-Diagram for if-else statement:
  • 11. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 11 Algorithm: Step1: Start Step2: Read „marks‟ Step3: If marks<40 Then Print “Fail” goto step4 Else If marks >=40 and marks<60 Then Print “Grade-C” goto step4 Else If marks>=60 and marks<75 Then Print “Grade-B” goto step4 Else If marks>=75 and marks<90 Then Print “Grade-A” goto step4 Else If marks>=90 Then Print “Grade-A+” goto step4 Else Print “Invalid” End If Step4: Stop
  • 12. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 12 Flowchart:
  • 13. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 13 Program: #include<stdio.h> #include<conio.h> void main() { int marks; clrscr(); printf(“n Enter marks:”); scanf(“%d”, &marks); if (marks<40) { printf(“n Fail”); } else if(marks>=40 && marks<60) { printf(“n Grade-C”); } else if(marks >=60 && marks <75) { printf(“n Grade-B”); } else if(marks>=75 && marks<90) { printf(“n Grade-A”); } else if(marks>90) { printf(“n Grade-A+”); } else { printf(“n Invalid”); }
  • 14. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 14 getch(); } Input: Enter marks: 65 Output: Grade-B Practice Problem Statements: 1) Write a program to enter the temperature and print the following message according to the given temperature by using else_if ladder statement. 1. T<=0 "Its very very cold". 2. 0 < T < 0 "Its cold". 3. 10 < T < =20 "Its cool out". 4. 20 < T < =30 "Its warm". 5. T>30 "Its hot". 2) Write a program to perform arithmetic operation based on user choice. First read two integer numbers from user and operator symbol e.g. +, -, *, / and %. Based on user choice perform arithmetic operation and display result. Here use ladder else_if construct. Input: Enter two numbers: 12 13 Enter operation: + Output: Addition of two numbers 12 & 13 is equal to 25 Conclusion: Thus a C program using else-if ladder statement, to display grades accordingly marks is implemented
  • 15. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 15 Learning Outcomes: At the end of this assignment, students are able to - explain decision control statements in C - write C code using else-if ladder in C - draw flowchart for decision making solutions
  • 16. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 16 Assignment#4d Program Statement: Write a C program using nested if_else statement, to display greater number amongst given three numbers a, b, & c grades accordingly marks. Learning Objectives: Students will be able to - explain decision control statements in C - write C code using else-if ladder in C - draw flowchart for decision making solutions Theory: Nested if_else construct:  In Nested if ..... else, the if and else part can contain one or more if else statements. General Form: if(conditional-expression) { if(conditional-expression) { statements; } else { statements; } statements; } else { if(conditional-expression) {
  • 17. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 17 statements; } statements; } Example: C code to check greater number amongst three given numbers a, b & c. if (a>b) { if(a>c) { printf(“%d is greater number”,a); } else { printf(“%d is greater number”,c); } } else { if(b>c) { printf(“%d is greater number”,b); } else { printf(“%d is greater number”,c); } }
  • 18. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 18 Flow-Diagram for if-else statement: Algorithm: Step1: Start Step2: Read two numbers A & B Step3: If A > B Then If A > C Then Print “A is greater number” Else Print “C is greater number” End If Else If B> C Then Print “B is greater number” Else Print “C is greater number” End If End If Step4: Stop
  • 19. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 19 Flowchart: Program: #include<stdio.h> #include<conio.h> void main() { int a, b, c; clrscr(); printf(“n Enter three numbers:”); scanf(“%d %d %d”, &a, &b, &c); if (a>b) {
  • 20. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 20 if(a>c) { printf(“n %d is greater number.”,a); } else { printf(“n %d is greater number.”,c); } } else { if(b>c) { printf(“n %d is greater number.”,a); } else { printf(“n %d is greater number.”,c); } } } Input: Enter three numbers: 10 30 20 Output: 30 is greater number. Practice Problem Statements: Write a C program to decide given number is divisible by 3 and 2 or 4 and 2 using nested if_else statement.
  • 21. C-Programming Walchand Institute of Technology (RC1131), Solapur Page 21 Conclusion: Thus a C program using nested if_else statement, to display greater number amongst given three numbers a, b, & c grades accordingly marks is implemented. Learning Outcomes: At the end of this assignment, students are able to - explain decision control statements in C - write C code using else-if ladder in C - draw flowchart for decision making solutions