Download - Control structers in c
![Page 1: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/1.jpg)
![Page 2: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/2.jpg)
Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring PartnerBaabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
![Page 3: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/3.jpg)
Week Target Achieved
1 40 22
2 40 27
3 40 27
Typing Speed
![Page 4: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/4.jpg)
Jobs AppliedWeek Company Designation Applied Date Current Status
1
2
3
![Page 5: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/5.jpg)
CONTROL STRUCTURES IN C PROGRAM
Name [email protected]
[email protected]/username
sreejith kappoortwitter.com/usernamein.linkedin.com/in/profilename
sreejithk/76/576/b99/Phonenumber 919562616566
![Page 6: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/6.jpg)
CONTROL STRUCTURES IN C PROGRAM
• C language possesses such decision making capabilities and supports the following statements known as control or decision-making statements.
• There are two types of statements.• Selection statement. • Iteration statement.
![Page 7: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/7.jpg)
Selection statements
• It provides decision making capability to a program and they alter normal flow of control based on their conditions. They are
• If• if else• if else if• switch
![Page 8: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/8.jpg)
Iteration statements
• It allows a set of instruction to be executed repeatedly based on some conditions. They are
• For loop• While
![Page 9: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/9.jpg)
SELECTION STATEMENT
![Page 10: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/10.jpg)
If statement
• The if statement is a powerful decision making statement and is used to control the flow of execution of statements.
• It is basically a two-way decision statement.
![Page 11: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/11.jpg)
IF ELSE
The if....else statement is an extension of the simple if statement. The general form is
if (condition){True-block statement(s)}else{False-block statement(s)}
![Page 12: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/12.jpg)
IF ELSE
PROGRAM TO KNOW THE NUMER IS POSITIVE OR NEGATIVE• void main()
{ int numb; printf ("Type any Number : "); scanf ("%d", &numb); if(numb > 0) { printf ("%d is the positive number", numb);}elseprintf ("%d is the Negative number", numb);}
![Page 13: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/13.jpg)
IF ELSE IF
• This makes selection from two alternatives.• If one is selected the other will be skipped.• But if the first one is not executed the second
one is selected.
![Page 14: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/14.jpg)
IF ELSE IF
Printf(“enter the character”);Scanf(“%c”,ch);If(ch>=‘a’ && ch<=‘z’)
printf(“it is lower case”);Else If(ch>=‘A’ && ch<=‘Z’);
printf(“it is upper case”);Else Printf(“it is special chara”);
program to print the character is uppercase or lowercase or special character
![Page 15: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/15.jpg)
Switch case
• Often a break statement is used as the last statement in each case's statement list
• A break statement causes control to transfer to the end of the switch statement
• If a break statement is not used, the flow of control will continue into the next case
![Page 16: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/16.jpg)
SWITCH• The general syntax of a switch statement is:
switch ( expression ){ case value1 : statement-list1 case value2 : statement-list2 case value3 : statement-list3 case ...
}
If expressionmatches value2,control jumpsto here
![Page 17: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/17.jpg)
Sample program for switch
Printf ("enter the game mode\n"); scanf ("%c“,&n); switch(n) { case '1' : printf("play game \n"); break; case '2' : printf("load game \n"); break;}
![Page 18: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/18.jpg)
ITERATION STATEMENTS
![Page 19: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/19.jpg)
while• The syntax of while statement in C:while (loop repetition condition)
statement• Loop repetition condition is the condition
which controls the loop.• The statement is repeated as long as the loop
repetition condition is true.• A loop is called an infinite loop if the loop
repetition condition is always true.
![Page 20: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/20.jpg)
An Example of a while Loop
5-20
Statement
Loop repetition condition
Loop control variable is the variable whose value controls loop repetition.
In this example, count_emp is the loop control variable.
![Page 21: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/21.jpg)
For loop
• The syntax of for statement in C:for (initialization expression;
loop repetition condition; update expression) statement
• The initialization expression set the initial value of the loop control variable.
• The loop repetition condition test the value of the loop control variable.
• The update expression update the loop control variable.
![Page 22: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/22.jpg)
An Example of the for Loop
To print the numbers printf("enter the first number"); scanf("%d",&n); printf("the numbers are\n"); { for(i=n;i<=100;i++) printf("%d ",&i);}
![Page 23: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/23.jpg)
If this presentation helped you, please visit our page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
![Page 24: Control structers in c](https://reader034.vdocuments.site/reader034/viewer/2022042814/555a5fd5d8b42a47748b5294/html5/thumbnails/24.jpg)
Contact Us
Emarald Mall (Big Bazar Building)Mavoor Road, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
NC Complex, Near Bus StandMukkam, Kozhikode,Kerala, India.Ph: + 91 – 495 40 25 550
Start up VillageEranakulam,Kerala, India.
Email: [email protected]