The document discusses various control structures in C programming including branching, looping, and nested control structures. It provides examples of if-else statements, if-else-if ladders, nested if-else statements, and switch statements. Key points covered include the syntax and flow of if-else, if-else-if, and switch statements as well as differences between switch and if-else structures. Sample programs demonstrate using control structures to check conditions, find largest of three numbers, and calculate grades.
BRANCHING STATEMENTS
if statement
if – else statement
if – else if ladder
Nested if
Goto
Switch case
programs
output
flowchart
Branching / Decision Making Statements
The statements in the program that helps to transfer the control from one part to other parts of the program.
Facilitates program in determining the flow of control
Involves decision making conditions
See whether the condition is satisfied or not
If statement; Execute a set of command line or one command line when the logical condition is true.
It has only one option
syntax with flowchart
If else if ladder; Number of logical statements are checked for executing various statement
If the first condition is true the compiler executes the block followed by first if condition.
If false it skips the block and checks for the next logical condition followed by else if.
Process is continued until a true condition is occurred or an else condition is satisfied.
Switch case; Multiway branch statement
It only requires one argument of any type, which is checked with number of cases.
If the value matches with the case constant, that particular case constant is executed. If not the default statement is executed.
Break statement – used to exit from current case structure
Nested if else; When a series of decisions are involved we use more than one if-else statement.
If condition is true control passes to first block i.e., if block. In this case there may be one more if block.
If condition is false control passes to else block. There we may have one more if block.
Introduction to control structure in C Programming Language include decision making (if statement, if..else statement, if...else if...else statement, nested if...else statement, switch...case statement), Loop(for loop, while loop, do while loop, nested loop) and using keyword(break, continue and goto)
Detailing about basics of C language and its control structure for learning C Language for beginners. It covers looping statement , control statement etc.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
BRANCHING STATEMENTS
if statement
if – else statement
if – else if ladder
Nested if
Goto
Switch case
programs
output
flowchart
Branching / Decision Making Statements
The statements in the program that helps to transfer the control from one part to other parts of the program.
Facilitates program in determining the flow of control
Involves decision making conditions
See whether the condition is satisfied or not
If statement; Execute a set of command line or one command line when the logical condition is true.
It has only one option
syntax with flowchart
If else if ladder; Number of logical statements are checked for executing various statement
If the first condition is true the compiler executes the block followed by first if condition.
If false it skips the block and checks for the next logical condition followed by else if.
Process is continued until a true condition is occurred or an else condition is satisfied.
Switch case; Multiway branch statement
It only requires one argument of any type, which is checked with number of cases.
If the value matches with the case constant, that particular case constant is executed. If not the default statement is executed.
Break statement – used to exit from current case structure
Nested if else; When a series of decisions are involved we use more than one if-else statement.
If condition is true control passes to first block i.e., if block. In this case there may be one more if block.
If condition is false control passes to else block. There we may have one more if block.
Introduction to control structure in C Programming Language include decision making (if statement, if..else statement, if...else if...else statement, nested if...else statement, switch...case statement), Loop(for loop, while loop, do while loop, nested loop) and using keyword(break, continue and goto)
Detailing about basics of C language and its control structure for learning C Language for beginners. It covers looping statement , control statement etc.
Welcome to WIPAC Monthly the magazine brought to you by the LinkedIn Group Water Industry Process Automation & Control.
In this month's edition, along with this month's industry news to celebrate the 13 years since the group was created we have articles including
A case study of the used of Advanced Process Control at the Wastewater Treatment works at Lleida in Spain
A look back on an article on smart wastewater networks in order to see how the industry has measured up in the interim around the adoption of Digital Transformation in the Water Industry.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
Explore the innovative world of trenchless pipe repair with our comprehensive guide, "The Benefits and Techniques of Trenchless Pipe Repair." This document delves into the modern methods of repairing underground pipes without the need for extensive excavation, highlighting the numerous advantages and the latest techniques used in the industry.
Learn about the cost savings, reduced environmental impact, and minimal disruption associated with trenchless technology. Discover detailed explanations of popular techniques such as pipe bursting, cured-in-place pipe (CIPP) lining, and directional drilling. Understand how these methods can be applied to various types of infrastructure, from residential plumbing to large-scale municipal systems.
Ideal for homeowners, contractors, engineers, and anyone interested in modern plumbing solutions, this guide provides valuable insights into why trenchless pipe repair is becoming the preferred choice for pipe rehabilitation. Stay informed about the latest advancements and best practices in the field.
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfKamal Acharya
The College Bus Management system is completely developed by Visual Basic .NET Version. The application is connect with most secured database language MS SQL Server. The application is develop by using best combination of front-end and back-end languages. The application is totally design like flat user interface. This flat user interface is more attractive user interface in 2017. The application is gives more important to the system functionality. The application is to manage the student’s details, driver’s details, bus details, bus route details, bus fees details and more. The application has only one unit for admin. The admin can manage the entire application. The admin can login into the application by using username and password of the admin. The application is develop for big and small colleges. It is more user friendly for non-computer person. Even they can easily learn how to manage the application within hours. The application is more secure by the admin. The system will give an effective output for the VB.Net and SQL Server given as input to the system. The compiled java program given as input to the system, after scanning the program will generate different reports. The application generates the report for users. The admin can view and download the report of the data. The application deliver the excel format reports. Because, excel formatted reports is very easy to understand the income and expense of the college bus. This application is mainly develop for windows operating system users. In 2017, 73% of people enterprises are using windows operating system. So the application will easily install for all the windows operating system users. The application-developed size is very low. The application consumes very low space in disk. Therefore, the user can allocate very minimum local disk space for this application.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Courier management system project report.pdfKamal Acharya
It is now-a-days very important for the people to send or receive articles like imported furniture, electronic items, gifts, business goods and the like. People depend vastly on different transport systems which mostly use the manual way of receiving and delivering the articles. There is no way to track the articles till they are received and there is no way to let the customer know what happened in transit, once he booked some articles. In such a situation, we need a system which completely computerizes the cargo activities including time to time tracking of the articles sent. This need is fulfilled by Courier Management System software which is online software for the cargo management people that enables them to receive the goods from a source and send them to a required destination and track their status from time to time.
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
Water scarcity is the lack of fresh water resources to meet the standard water demand. There are two type of water scarcity. One is physical. The other is economic water scarcity.
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
2. Three kinds of execution flow
◦ Sequence:
The execution of the program is sequential.
◦ Selection / Branching
A control structure which chooses alternative to execute/program chooses to
follow one branch or another
Example: if, if/else, switch, Conditional operator
◦ Repetition / Looping
A control structure which repeats a group of statements.
Example: while, do/while, for, nested loops, break ,
continue.
2
4. The simple if Statement
The if statement has the following syntax:
4
if ( condition )
statement;
if is a C
reserved word
Condition is an expression that is
either false (represented by 0) or
true (represented by 1/non-zero).
If the condition is true, the statement is executed.
If the condition is false, the statement is not executed ,control
comes out
6. The if-else Statement
An if statement can be followed by an optional else statement,
which executes when the boolean expression is false.
Syntax:
if(boolean_expression) // eg: A>0
{
True statements; // A is positive
else
{
False statements; //B is negative
}
6
7. The if-else Statement- flow
void main()
{
int age;
scanf(“age=%d “,&age);
if (age>= 18)
{
printf(“Eligible");
}
else
printf(“Not eligible”);
}
7
OUTPUT 1
Age=30
Eligible
OUTPUT 2
Age=12
Not Eligible
8. The if-else Statement-Program to find the given number is odd or even
#include <stdio.h>
void main( )
{
int num;
printf("Enter a number you want to check.n");
scanf("%d",&num);
if((num%2)==0) //checking whether remainder is 0 or not.
printf("%d is even.",num);
else
printf("%d is odd.",num);
}
8
OUTPUT
Enter a number you want to check.
25
25 is odd.
Enter a number you want to check.
2
2 is even.
9. Sample programs
In a company an employee is paid as under:
If his basic salary is less than Rs. 1500,
then HRA = 10% of basic salary and
DA = 90% of basic salary.
If his salary is either equal to or above Rs. 1500,
then HRA = Rs. 500 and DA = 98% of basic salary.
If the employee's salary is input through the keyboard
write a program to find his gross salary.
9
10. /* Calculation of gross salary */
void main( )
{
float bs, gs, da, hra ;
printf ( "Enter basic salary " ) ;
scanf ( "%f", &bs ) ;
if ( bs < 1500 )
{
hra = bs * 10 / 100 ;
da = bs * 90 / 100 ;
}
else
{
hra = 500 ;
da = bs * 98 / 100 ;
}
gs = bs + hra + da ;
printf ( "gross salary = Rs. %f", gs ) ;
}
10
11. (if...elseif....else / else-if ladder Statement)
The if...else if statement is used when program requires more than one test expression
if (test expression1)
{
statement/s to be executed if test expression1 is true;
}
else if(test expression2)
{
statement/s to be executed if test expression1 is false and 2 is true;
}
.
.
.
.
else
{
statements to be executed if all test expressions are false;
}
11
12. To print given number is positive or negative or
zero-using elseif ladder
#include <stdio.h>
int main()
{
int num;
printf("Enter a number n");
scanf("%d",&num);
if (num > 0)
{
printf(“number %d is
positiven“,num);
}
12
else if (num < 0)
{
printf(“number %d is
negativen“,num);
}
else if (num = = 0)
{
printf(“number is zero “);
}
printf(“Thank you”);
}
13. Nested if else Statement
It is always legal in C programming to nest if-else statements, which means you can
use one if or else if statement inside another if or else
Syntax:
if(cond 1)
{
/* Executes when the boolean expression 1 is true */
if(cond 2)
{
/* Executes when the boolean expression 2 is true */
}
else
{ /* Executes when the boolean expression 2 is false */
}
}
else
{ if(cond3)
{
/* Executes when the boolean expression 3 is true */
}
else
{ /* Executes when the boolean expression 3 is false */
} 13
14. Largest of three numbers-Nested if else Statement
#include <stdio.h>
void main ()
{
int a, b,c ;
printf(“enter values a,b and cn”);
scanf(“%d%d%d”,a&a,&b,&c);
if( a >b )
{
if( a>c)
{
printf("a is largestn" );
}
else
{
printf(“c is largestn" );
}
}
14
else
{
if( b> c )
{
printf(“b is largestn" );
}
else
{
printf(“c is largestn" );
}
}
}
15. Nested if else Statement
#include <stdio.h>
int main ()
{
int a = 100;
int b = 200;
if( a == 100 )
{
if( b == 200 )
{
printf("Value of a is 100 and b is 200n" );
}
}
printf("Exact value of a is : %dn", a );
printf("Exact value of b is : %dn", b );
return 0;
}
15
OUTPUT
Value of a is 100 and b is 200
Exact value of a is : 100
Exact value of b is : 200
16. Sample programs
The marks obtained by a student in 5 different subjects
are input through the keyboard. The student gets a
division as per the following rules:
Percentage above or equal to 60 - First division
Percentage between 50 and 59 - Second division
Percentage between 40 and 49 - Third division
Percentage less than 40 - Fail
Write a program to calculate the division obtained by the
student.
16
17. main( )
{
int m1, m2, m3, m4, m5, per ;
printf ( "Enter marks in five subjects " ) ;
scanf ( "%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5 ) ;
per = ( m1 + m2 + m3 + m4 + m5 ) / 5 ;
if ( per >= 60 )
printf ( "First division ") ;
else
{
if ( per >= 50 )
printf ( "Second division" ) ;
else
{
if ( per >= 40 )
printf ( "Third division" ) ;
else
printf ( "Fail" ) ;
}
}
}
17
18. main( )
{
int m1, m2, m3, m4, m5, per ;
printf ( "Enter marks in five subjects " ) ;
scanf ( "%d %d %d %d %d", &m1, &m2, &m3, &m4, &m5 ) ;
per = ( m1 + m2 + m3 + m4 + m5 ) / 5 ;
if ( per >= 60 )
printf ( "First division" ) ;
if ( ( per >= 50 ) && ( per < 60 ) )
printf ( "Second division" ) ;
if ( ( per >= 40 ) && ( per < 50 ) )
printf ( "Third division" ) ;
if ( per < 40 )
printf ( "Fail" ) ;
}
18
19. main( )
{
int m1, m2, m3, m4, m5, per ;
per = ( m1+ m2 + m3 + m4+ m5 ) / per ;
if ( per >= 60 )
printf ( "First division" ) ;
else if ( per >= 50 )
printf ( "Second division" ) ;
else if ( per >= 40 )
printf ( "Third division" ) ;
else
printf ( "fail" ) ;
}
19
20. A certain grade of steel is graded according to the following conditions:
(i) Hardness must be greater than 50
(ii) Carbon content must be less than 0.7
(iii) Tensile strength must be greater than 5600
The grades are as follows: Grade is 10 if all three conditions are met
Grade is 9 if conditions (i) and (ii) are met
Grade is 8 if conditions (ii) and (iii) are met
Grade is 7 if conditions (i) and (iii) are met
Grade is 6 if only one condition is met
Grade is 5 if none of the conditions are met
Write a program, which will require the user to give values of hardness, carbon
content and tensile strength of the steel under consideration and output the grade
of the steel.
20
21. Calculate the EB bill using if-else-if ladder
Get the no. of units (n)
Units 1 to 100 Amount: Rs. 3.00 per unit
Units 101 to 250 Amount: Rs. 4.50 per unit
Units 251 to 350 Amount: Rs. 5.00 per unit
More than 350 Amount: Rs. 7.00 per unit
21
22. To print ASCIIvalues(ifelseif)
Any character is entered through the keyboard, write a
program to determine whether the character entered is
a capital letter, a small case letter, a digit or a special
symbol. The following table shows the range of ASCII
values for various characters.
22
Characters
A – Z
a – z
0 – 9
special symbols
ASCII Values
65 – 90
97 – 122
48 – 57
0 - 47, 58 - 64,
91 - 96, 123 - 127
24. Switch Statement Syntax
switch(expr/var)
{
case constant-expression :
statement(s);
break; /* optional */
case constant-expression :
statement(s);
break; /* optional */
/* you can have any number of case statements */
default : /* Optional */
}
24
26. 26
main( )
{
int i = 2 ;
switch ( i )
{
case 1 :
printf ( "I am in case 1 n" ) ;
case 2 :
printf ( "I am in case 2 n" ) ;
case 3 :
printf ( "I am in case 3 n" ) ;
default :
printf ( "I am in default n" ) ;
}
}
The output of this program would be:
I am in case 2
I am in case 3
I am in default
27. 27
main( )
{
int i = 22 ;
switch ( i )
{
case 121 :
printf ( "I am in case 121 n" ) ;
break ;
case 7 :
printf ( "I am in case 7 n" ) ;
break ;
case 22 :
printf ( "I am in case 22 n" ) ;
break ;
default :
printf ( "I am in default n" ) ;
}
}
The output of this program would be:
I am in case 22
28. 28
void main()
{
char c = 'x' ;
switch ( c )
{
case 'v' :
printf ( "I am in case v n" ) ;
break ;
case 'a' :
printf ( "I am in case a n" ) ;
break ;
case 'x' :
printf ( "I am in case x n" ) ;
break ;
default :
printf ( "I am in default n" ) ;
}
}
The output of this program would be:
I am in case x
29. Example 1
scanf(“%d”, &day);
switch ( day )
{
case 0:
printf (“Sundayn”) ;
break ;
case 1:
printf (“Mondayn”) ;
break ;
case 2:
printf (“Tuesdayn”) ;
break ;
case 3:
printf (“Wednesdayn”);
break ;
case 4:
printf (“Thursdayn”) ;
break ;
case 5:
printf (“Fridayn”) ;
break ;
case 6:
printf (“Saturdayn”) ;
break ;
default:
printf (“Error -- invalid
day.n”) ;
break ;
}
29
30. Example 2
#include<stdio.h>
void main()
{
char a;
printf("Enter any Alphabet : ");
scanf("%c",&a);
switch (a)
{
case'A':
case'a':
case'E':
case'e':
case‘I':
case'i':
case'O':
case'o':
case'U':
case'u': printf("It is a Vowel");
break;
default: printf("It is a Consonent");
}
}
30
31. Example 3
#include <stdio.h>
int main ()
{
char grade;
scanf(“%c”, &grade);
switch(grade)
{
case 'A' :
printf("Excellent!n" );
break;
case 'B' :
case 'C' :
printf("Well donen" );
break;
case 'D' :
printf("You passedn" );
break;
case 'F' :
printf("Better try againn" );
break;
default :
printf("Invalid graden" );
}
printf("Your grade is %cn",
grade ); }
31
32. Example 4
#include <stdio.h>
int main ()
{
int a,b,c,choice;
scanf(“%d %d”, &a,&b);
printf(“Menu 1.Add 2.Sub
3.Mul 4.Div 5.Modn”);
scanf(“%d”,&choice);
switch(choice)
{
case 1 :c=a+b;
printf(“Sum is %dn“,c );
break;
case 2:c=a-b;
printf(“Difference is %dn“,c );
break;
case 3:c=a*b;
printf(“Multiply is %dn“,c );
break;
case 4:c=a/b;
printf(“Division is %dn“,c );
break;
case 5:c=a%b;
printf(“Remainder is %dn“,c );
break;
default :
printf("Invalid Choicen" );
} } 32
33. Cannot do with switch:
1. A float expression cannot be tested .
2. Cases cannot have variable expressions(eg: case a+3)
3. Multiple cases cannot use same expressions
Eg: case 3: case 1+2:
Switch is faster than if-else ladder when more conditions
to be tested (because switch matches the value but in if-
else all conditions are evaluated)
33
Switch vs if-else ladder
34. Switch vs if-else ladder
A nested if-else structure is just as efficient as a switch
statement.
However, a switch statement may be easier to read.
Also, it is easier to add new cases to a switch
statement than to a nested if-else structure.
34