Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
College aantekeningen

branching and looping in c

Beoordeling
-
Verkocht
-
Pagina's
20
Geüpload op
25-03-2023
Geschreven in
2022/2023

gives a brief and detailed study of branching and looping in c language

Instelling
Vak

Voorbeeld van de inhoud

BRANCHING and LOOPING
BRANCHING
What are Control flow statements?

 A program is set of instructions.
 By default these instructions are sequentially executed.
 Definition: The statements that transfers the control from one part of the program to another part of the
program ,with or without any condition is called as branching statements.


Types of Branching statements/Conditional statements/decision making statements/
Control construct
There are 2 types of branching statements present 1.Conditional Statement
2. Unconditional Statement.


1. Conditional Statement
 Definition: The statements that transfers the control from one part of the program to another part of the
program based on a condition is called as Conditional statements.
There are 5 Conditional statements in C

1. if control construct(simple if)
2. if else control construct
3. nested if else control construct
4. else if ladder or cascaded
5. switch control construct


The if statement (Simple if/ One way selection)
 An if statement is a single selection statement.
 It is used to execute a set of statements if the condition is true,
 If the condition is false, it skips executing those set of statements. Hence it is called one way selection.

, Syntax: Flowchart:
Statement a1;
……………
Statement a1;
Statement an;
……..
Statement an;
if(condition)
if False
{ condition
Statement t1;
…………..
True
Statement tn;
Statement t1;
} …………….
Statement tn;
Statement b1;
……..
Statement bn;
Statement b1;
……………

Statement bn;
Explanation
 The keyword if must be followed by an expression and expression must be enclosed within parentheses.
 First statement a1 to an is executed sequentially(one after another).
 The if statement is executed next. The expression inside the parentheses is evaluated. i.e Condition is
checked, which results in either TRUE or FALSE .
 If condition is TRUE the statements t1 to tn are executed and then statements b1 to bn are executed.
 If condition is FALSE the statements t1 to tn are skipped and then statements b1 to bn are executed.


Advantage of if-statement
 Output of if-statement is true or false.
 if-statement is used as one way decision/selection statement.

Disadvantage
 If one action has to be performed when the condition is true and another action has to be performed
when the condition is false then if-statement is not recommended
 This disadvantage is overcome using two- way decision/selection statement called “ if-else statement”

, An Example which illustrates if statement: To print given no is an even no.
Algorithm Flowchart Program

Algorithm: Check even number #include<stdio.h>
Input: A number void main()
Output: Even Number {
Step 1: Start int n;
Step 2: [input the number] printf(“ Enter the number\n”)
Read N scanf(“%d”,&n); if(n
Step 3: [compute even number] %2==0)
if n%2 is equals to zero {
Goto step 4 printf(“Even no”);
Otherwise goto step 5 }
Step 4: [display output]
Print “even no” }
Step 5: Stop


Note: Similarly write Algorithm, Flowchart and C Program for the following
i) To print given no is a odd no. Logic: if (n!=0)
ii) To print given no is a positive no. Logic: if(n>0)
iii) To print given no is a negative no.Logic: if(n<0)

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
25 maart 2023
Aantal pagina's
20
Geschreven in
2022/2023
Type
College aantekeningen
Docent(en)
Dr karthik
Bevat
Alle colleges

Onderwerpen

$8.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
hemantkumar1

Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
hemantkumar1 nmit
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
3 jaar
Aantal volgers
0
Documenten
7
Laatst verkocht
-

0.0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen