SlideShare a Scribd company logo
1 of 33
 Control flow statement is a statement whose execution 
results in a choice being made as to which of two or more 
paths should be followed. 
 Control flow statements can be categorized by their effect: 
a. continuation at a different statement (unconditional 
branch or jump) 
b. executing a set of statements only if some condition is 
met (choice - i.e. conditional branch) 
c. executing a set of statements zero or more times, until 
some condition is met (i.e. loop - the same as conditional 
branch) 
d. executing a set of distant statements, after which the flow 
of control usually returns (subroutines and continuations), 
e. stopping the program, preventing any further execution 
(unconditional halt).
Start 
Enter hpmn 
If(hpnm>3.7) 
Finish 
Yes 
No 
Very Good
#include<stdio.h> 
#include<conio.h> 
main() 
{ 
clrscr(); 
float hpmn; 
printf("Enter the hpmn :"); 
scanf("%f",&hpmn); 
if(hpmn>3.7) 
{ 
printf("Very Good"); 
} 
return 0; 
}
Start 
Enter 
hpmn 
No Yes 
If(hpnm>3.7 
) 
Try Again! Very Good 
Finish
#include<stdio.h> 
#include<conio.h> 
main() 
{ 
clrscr(); 
float hpmn; 
printf("Enter the hpmn :"); 
scanf("%f",&hpmn); 
if(hpmn>3.7) 
{ 
printf("Very Good"); 
} 
else 
{ 
printf("Try Again!"); 
} 
return 0; 
}
Start 
Enter Password 
If(pass== 
1234) 
No Yes 
Finish 
Enter 
Wrong Money 
Passwor 
d If(money 
No Yes 
<10) 
No 
Money 
Take the 
money
#include<stdio.h> 
#include<conio.h> 
main() 
{ 
clrscr(); 
int pass; 
float money; 
printf("Enter the Password :"); 
scanf("%d",&pass); 
if(pass==1234) 
{ 
printf("Enter the money :"); 
scanf("%f",&money); 
if(money<10) 
{ 
printf("Not enough balance"); 
} 
else 
{ 
printf("Take the money"); 
} 
} 
else 
{ 
printf("Wrong Password!"); 
} 
return 0; 
}
Start 
Chose 
Month 
switch 
(month) 
Finish 
Januar 
y 
Februar 
y 
Mac 
Decemb 
er 
………...
#include<stdio.h> 
#include<conio.h> 
main() 
{ 
clrscr(); 
int month; 
printf("Enter a month :"); 
scanf("%d",&month); 
switch(month) 
{ 
case 1: printf("January"); 
break; 
case 2: printf("February"); 
break; 
case 3: printf("Mac"); 
break; 
case 4: printf("April"); 
break; 
case 5: printf("May"); 
break; 
case 6: printf("Jun"); 
break; 
case 7: printf("July"); 
break; 
case 8: printf("Ogos"); 
break; 
case 9: printf("September"); 
break; 
case 10:printf("October"); 
break; 
case 11:printf("Novenber"); 
break; 
case 12:printf("December"); 
break; 
default:printf("error!"); 
break; 
} 
return 0; 
}
#include<stdio.h> 
#include<conio.h> 
main() 
{ 
clrscr(); 
int grade; 
printf("Enter a month :"); 
scanf("%d",&grade); 
switch(grade) 
{ 
case 10: 
case 9: printf("Grade: A "); 
break; 
case 8: printf("Grade: B "); 
break; 
case 7: printf("Grade: C "); 
break; 
case 6: printf("Grade: D "); 
break; 
case 5: 
case 4: 
case 3: 
case 2: 
case 1: printf("Grade: F "); 
break; 
default: printf("error!"); 
break; 
} 
return 0; 
}
Score 
>=90 
Grede 
= A 
Finish 
Score 
>=80 
Score 
>=70 
Score 
>=60 
Grede 
= B 
Grede 
= C 
Grede 
Grede = D 
= F
#include<stdio.h> 
#include<conio.h> 
main() 
{ 
clrscr(); 
int score; 
printf("Enter the test score (0-100) :"); 
scanf("%d",&score); 
if(score >=90) 
{ 
printf("Gred: A"); 
} 
else if(score >=80) 
{ 
printf("Gred: B"); 
} 
else if(score >=70) 
{ 
printf("Gred: C"); 
} 
else if(score >=60) 
{ 
printf("Gred: D"); 
} 
else 
{ 
printf("Gred: F"); 
} 
return 0; 
}
 Is a pretest loop 
 Use an expression to control the loop 
 It test the expression before ever iteration 
of the loop
#include<stdio.h> 
main() 
{ 
int pembilang; 
float purata,jumlah,score; 
pembilang=1; 
jumlah=0; 
while(pembilang<=5) 
{ 
printf("nPlease enter your test score %d:",pembilang); 
scanf("%f",&score); 
jumlah=score+jumlah; 
pembilang++; 
printf("njumlah is :%.2f",jumlah); 
} 
purata=(jumlah/5); 
printf("nnAverage test scores are is %.2f",purata); 
return 0; 
}
 Is a pretest loop that uses three 
expressions 
 The first expression contains any 
initialization statements, the second 
contains the terminating expression and 
the third contains the updating 
expression
#include<stdio.h> 
main() 
{ 
int counter; 
float average,sum,score; 
sum=0; 
for(counter=1; counter<=5; counter++) 
{ 
printf("nPlease enter your test score %d:", counter); 
scanf("%f",&score); 
sum=score+sum; 
printf("nThe sum is :%.2f",sum); 
} 
average=(sum/5); 
printf("nnAverage test scores are is %.2f",average); 
return 0; 
}
 Is a post-test loop 
 Use an expression to control the loop 
 It test the expression after the execution 
of the body
#include<stdio.h> 
main() 
{ 
int pembilang; 
float purata,jumlah,score; 
pembilang=1; 
jumlah=0; 
do 
{ 
printf("nPlease enter your test score %d:",pembilang); 
scanf("%f",&score); 
jumlah=score+jumlah; 
printf("njumlah is :%.2f",jumlah); 
pembilang++; 
} 
while(pembilang<=5); 
purata=(jumlah/5); 
printf("nnAverage test scores are is %.2f",purata); 
return 0; 
}
 These loops are the loops which contain 
another looping statement in a single loop. 
 These types of loops are used to create 
matrix. 
 Any loop can contain a number of loop 
statements in itself. 
 If we are using loop within loop that is 
called nested loop. 
 In this the outer loop is used 
for counting rows and the internal loop is 
used for counting column
#include<stdio.h> 
main() 
{ 
int i,j; 
for(i=1;i<=5;i++) 
{ 
for(j=1;j<=10;j++) 
{ 
printf("*"); 
} 
printf("n"); 
} 
return 0; 
} 
output 
********** 
********** 
********** 
********** 
**********
 The C language provides a capability that enables the user 
to define a set of ordered data items known as an array. 
 Suppose we had a set of grades that we wished to read 
into the computer and suppose we wished to perform some 
operations on these grades, we will quickly realize that we 
cannot perform such an operation until each and every 
grade has been entered since it would be quite a tedious 
task to declare each and every student grade as a variable 
especially since there may be a very large number. 
 In C we can define variable called grades, which 
represents not a single value of grade but a entire set of 
grades. Each element of the set can then be referenced by 
means of a number called as index number or subscript.
 Like any other variable arrays must be 
declared before they are used. The general 
form of declaration is: 
type variable-name[size]; 
 The type specifies the type of the elements 
that will be contained in the array, such as 
int float or char and the size indicates the 
maximum number of elements that can be 
stored inside the array for ex: 
float height[50]; 
int week[7];
 The declaration int values[10]; would reserve 
enough space for an array called values that 
could hold up to 10 integers. Refer to the below 
given picture to conceptualize the reserved 
storage space. 
values[0] 
values[1] 
values[2] 
values[3] 
values[4] 
values[5] 
values[6] 
values[7] 
values[8] 
values[9] 
 The array values stored in the memory.
 We can initialize the elements in the array in the same way as the ordinary variables when 
they are declared. The general form of initialization off arrays is: 
type array_name[size]={list of values}; 
 The values in the list care separated by commas, for example the statement 
int number[3]={0,0,0}; 
 Will declare the array size as a array of size 3 and will assign zero to each element if the 
number of values in the list is less than the number of elements, then only that many 
elements are initialized. The remaining elements will be set to zero automatically. 
 In the declaration of an array the size may be omitted, in such cases the compiler 
allocates enough space for all initialized elements. For example the statement 
int counter[]={1,1,1,1}; 
 Will declare the array to contain four elements with initial values 1. this approach works 
fine as long as we initialize every element in the array. 
 The initialization of arrays in c suffers two draw backs 
1. There is no convenient way to initialize only selected elements. 
2. There is no shortcut method to initialize large number of elements.
Arrays of Greater Dimension 
One-dimensional arrays are linear containers. 
© 2006 Pearson Addison-Wesley. 
12.5.26 All rights reserved 
Multi-dimensional Arrays 
[0] [1] [2] 
[0] 
[0] [1] [2] [3] 
[1] 
[2] 
two-dimensional 
[0] 
[0] [1] [2] [3] [4] 
[1] 
[2] 
[3] 
[2] 
[1] 
[0] 
three-dimensional
Initializing Multi-dimensional Arrays 
© 2006 Pearson Addison-Wesley. 
12.5.27 All rights reserved 
[0] 
[0] [1] [2] [3] 
[1] 
[2] 
[0] 
[0] [1] [2] [3] [4] 
[1] 
[2] 
[3] 
[2] 
[1] 
[0] 
[0] [1] [2] 
declaration instantiation 
Oval[] circles; circles = new Oval[3]; 
double[][] table; table = new double[3][4]; 
int[][][] arr; arr = new int[4][5][3];
How many cells in each of the following? 
double[][] distance = new double[10][15]; 
int[][][] cube = new int[8][8][10]; 
String[][][][][] words = new String[5][4][5][12][6]; 
© 2006 Pearson Addison-Wesley. 
12.5.28 All rights reserved
Creating Multi-dimensional Arrays 
The initialization notation for 1D arrays can be extended. 
char[][] words = { {'c', 'i', 'p', 'h', 'e', 'r'}, 
{'h', 'i', 'c', 'c’, 'u', 'p'}, 
{'a', 'p', 'i', 't', 'c', 'h'} }; 
© 2006 Pearson Addison-Wesley. 
12.5.29 All rights reserved 
[0] 
[0] [1] [2] [3] [4] [5] 
[1] 
[2] 
c i p h e 
h i c c u 
a p i t c 
r 
p 
h 
Exercise 
How would you duplicate this behavior without the initialization 
notation?
Processing Multi-dimensional Arrays 
The key to processing all cells of a multi-dimensional array is nested 
loops. 
12.5.30 
[0] [1] [2] [3] 
[0] 
[1] 
[2] 
10 11 12 13 
14 15 16 17 
18 19 20 21 
22 23 24 25 
26 27 28 29 
[3] 
[4] 
for (int row=0; row!=5; row++) { 
for (int col=0; col!=4; col++) { 
System.out.println( myArray[row][col] ); 
} 
} 
for (int col=0; col!=4; col++) { 
for (int row=0; row!=5; row++) { 
System.out.println( myArray[row][col] ); 
} 
} 
Exercises 
1) Write a method to initialize this array with the given values. 
2) Write a method to interchange two columns, indexed by two int 
parameters.
Atlanta Chicago Dallas Los Angelas New York City 
Atlanta 0 722 2244 800 896 
Chicago 722 0 1047 2113 831 
Dallas 2244 1047 0 1425 1576 
Los Angeles 800 2113 1425 0 2849 
New York City 896 831 1576 2849 0 
private final int[] mileage = {{0, 722, 2244, 800, 896}, 
{722, 0, 1047, 2113, 831}, 
{2244, 1047, 0, 1425, 1576}, 
{800, 2113, 1425, 0, 2849, 
{896, 831, 1576, 2849, 0} }; 
© 2006 Pearson Addison-Wesley. 
Tables 
12.5.31 All rights reserved 
private final int atlanta = 0; 
private final int chicago = 1; 
private final int dallas = 2; 
private final int losAngelas = 3; 
private final int newYork = 4;
#include<stdio.h> 
main( ) 
{ 
int bil,data[10]={10,20,-5,36,-95,14,-82,0,1,25}; 
printf("Please select the value to be viewed [0-9]:"); 
scanf("%d",&bil); 
printf("nValue in data %d is %d",bil,data[bil]); 
return 0; 
} 
output 
Please select the value to be viewed [0-9]: 8 
Value in data 8 is 1
#include<stdio.h> 
main( ) 
{ 
int data[50],saiz,kira_neg=0,kira_pos=0,count,bil; 
printf("Enter the size of the arrayn :"); 
scanf("%d",&saiz); 
for (count=0;count<saiz;count++) 
{ 
for(count=0;count<saiz;count++) 
{ 
bil=count+1; 
printf("nEnter the elements of the arrayn %d:",bil); 
scanf("%d",&data[count]); 
if(data[count]<0) 
kira_neg++; 
else 
kira_pos++; 
} 
} 
printf("nThere are %d positive numbers and %d negative numbers in the arrays",kira_pos,kira_neg); 
return 0; 
}

More Related Content

What's hot

Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointerNishant Munjal
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statementsMomenMostafa
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and stringsRai University
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsRai University
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsRai University
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-aneebkmct
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsRai University
 
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++Muhammad Hammad Waseem
 

What's hot (20)

C pointers and references
C pointers and referencesC pointers and references
C pointers and references
 
Array, string and pointer
Array, string and pointerArray, string and pointer
Array, string and pointer
 
4 operators, expressions &amp; statements
4  operators, expressions &amp; statements4  operators, expressions &amp; statements
4 operators, expressions &amp; statements
 
Python unit 3 and Unit 4
Python unit 3 and Unit 4Python unit 3 and Unit 4
Python unit 3 and Unit 4
 
C programming slide c05
C programming slide c05C programming slide c05
C programming slide c05
 
Unit3 C
Unit3 C Unit3 C
Unit3 C
 
function, storage class and array and strings
 function, storage class and array and strings function, storage class and array and strings
function, storage class and array and strings
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
Lecture 9- Control Structures 1
Lecture 9- Control Structures 1Lecture 9- Control Structures 1
Lecture 9- Control Structures 1
 
Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Functions torage class and array and strings-
Functions torage class and array and strings-Functions torage class and array and strings-
Functions torage class and array and strings-
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
Arrays
ArraysArrays
Arrays
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Unit 2
Unit 2Unit 2
Unit 2
 
Pointer
PointerPointer
Pointer
 
Unitii string
Unitii stringUnitii string
Unitii string
 
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
 

Similar to CHAPTER 5

Similar to CHAPTER 5 (20)

COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Arrays in C language
Arrays in C languageArrays in C language
Arrays in C language
 
Array
ArrayArray
Array
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
3. chapter ii
3. chapter ii3. chapter ii
3. chapter ii
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Ch08
Ch08Ch08
Ch08
 
Array and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdfArray and its types and it's implemented programming Final.pdf
Array and its types and it's implemented programming Final.pdf
 
Arrays
ArraysArrays
Arrays
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Arrays
ArraysArrays
Arrays
 
02 arrays
02 arrays02 arrays
02 arrays
 
presentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.pptpresentation_arrays_1443553113_140676.ppt
presentation_arrays_1443553113_140676.ppt
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Array
ArrayArray
Array
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 

More from mohd_mizan

Mind map chapter 4
Mind map chapter 4Mind map chapter 4
Mind map chapter 4mohd_mizan
 
Dbs 1012 synopsis
Dbs 1012 synopsisDbs 1012 synopsis
Dbs 1012 synopsismohd_mizan
 
Chapter 4 work, energy and power
Chapter 4 work, energy and powerChapter 4 work, energy and power
Chapter 4 work, energy and powermohd_mizan
 

More from mohd_mizan (8)

Mind map chapter 4
Mind map chapter 4Mind map chapter 4
Mind map chapter 4
 
Dbs 1012 synopsis
Dbs 1012 synopsisDbs 1012 synopsis
Dbs 1012 synopsis
 
Chapter 4 work, energy and power
Chapter 4 work, energy and powerChapter 4 work, energy and power
Chapter 4 work, energy and power
 
CHAPTER 3
CHAPTER 3CHAPTER 3
CHAPTER 3
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
 
CHAPTER 6
CHAPTER 6CHAPTER 6
CHAPTER 6
 
CHAPTER 2
CHAPTER 2CHAPTER 2
CHAPTER 2
 
CHAPTER 1
CHAPTER 1CHAPTER 1
CHAPTER 1
 

Recently uploaded

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 

Recently uploaded (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 

CHAPTER 5

  • 1.
  • 2.  Control flow statement is a statement whose execution results in a choice being made as to which of two or more paths should be followed.  Control flow statements can be categorized by their effect: a. continuation at a different statement (unconditional branch or jump) b. executing a set of statements only if some condition is met (choice - i.e. conditional branch) c. executing a set of statements zero or more times, until some condition is met (i.e. loop - the same as conditional branch) d. executing a set of distant statements, after which the flow of control usually returns (subroutines and continuations), e. stopping the program, preventing any further execution (unconditional halt).
  • 3. Start Enter hpmn If(hpnm>3.7) Finish Yes No Very Good
  • 4. #include<stdio.h> #include<conio.h> main() { clrscr(); float hpmn; printf("Enter the hpmn :"); scanf("%f",&hpmn); if(hpmn>3.7) { printf("Very Good"); } return 0; }
  • 5. Start Enter hpmn No Yes If(hpnm>3.7 ) Try Again! Very Good Finish
  • 6. #include<stdio.h> #include<conio.h> main() { clrscr(); float hpmn; printf("Enter the hpmn :"); scanf("%f",&hpmn); if(hpmn>3.7) { printf("Very Good"); } else { printf("Try Again!"); } return 0; }
  • 7. Start Enter Password If(pass== 1234) No Yes Finish Enter Wrong Money Passwor d If(money No Yes <10) No Money Take the money
  • 8. #include<stdio.h> #include<conio.h> main() { clrscr(); int pass; float money; printf("Enter the Password :"); scanf("%d",&pass); if(pass==1234) { printf("Enter the money :"); scanf("%f",&money); if(money<10) { printf("Not enough balance"); } else { printf("Take the money"); } } else { printf("Wrong Password!"); } return 0; }
  • 9. Start Chose Month switch (month) Finish Januar y Februar y Mac Decemb er ………...
  • 10. #include<stdio.h> #include<conio.h> main() { clrscr(); int month; printf("Enter a month :"); scanf("%d",&month); switch(month) { case 1: printf("January"); break; case 2: printf("February"); break; case 3: printf("Mac"); break; case 4: printf("April"); break; case 5: printf("May"); break; case 6: printf("Jun"); break; case 7: printf("July"); break; case 8: printf("Ogos"); break; case 9: printf("September"); break; case 10:printf("October"); break; case 11:printf("Novenber"); break; case 12:printf("December"); break; default:printf("error!"); break; } return 0; }
  • 11. #include<stdio.h> #include<conio.h> main() { clrscr(); int grade; printf("Enter a month :"); scanf("%d",&grade); switch(grade) { case 10: case 9: printf("Grade: A "); break; case 8: printf("Grade: B "); break; case 7: printf("Grade: C "); break; case 6: printf("Grade: D "); break; case 5: case 4: case 3: case 2: case 1: printf("Grade: F "); break; default: printf("error!"); break; } return 0; }
  • 12. Score >=90 Grede = A Finish Score >=80 Score >=70 Score >=60 Grede = B Grede = C Grede Grede = D = F
  • 13. #include<stdio.h> #include<conio.h> main() { clrscr(); int score; printf("Enter the test score (0-100) :"); scanf("%d",&score); if(score >=90) { printf("Gred: A"); } else if(score >=80) { printf("Gred: B"); } else if(score >=70) { printf("Gred: C"); } else if(score >=60) { printf("Gred: D"); } else { printf("Gred: F"); } return 0; }
  • 14.  Is a pretest loop  Use an expression to control the loop  It test the expression before ever iteration of the loop
  • 15. #include<stdio.h> main() { int pembilang; float purata,jumlah,score; pembilang=1; jumlah=0; while(pembilang<=5) { printf("nPlease enter your test score %d:",pembilang); scanf("%f",&score); jumlah=score+jumlah; pembilang++; printf("njumlah is :%.2f",jumlah); } purata=(jumlah/5); printf("nnAverage test scores are is %.2f",purata); return 0; }
  • 16.  Is a pretest loop that uses three expressions  The first expression contains any initialization statements, the second contains the terminating expression and the third contains the updating expression
  • 17. #include<stdio.h> main() { int counter; float average,sum,score; sum=0; for(counter=1; counter<=5; counter++) { printf("nPlease enter your test score %d:", counter); scanf("%f",&score); sum=score+sum; printf("nThe sum is :%.2f",sum); } average=(sum/5); printf("nnAverage test scores are is %.2f",average); return 0; }
  • 18.  Is a post-test loop  Use an expression to control the loop  It test the expression after the execution of the body
  • 19. #include<stdio.h> main() { int pembilang; float purata,jumlah,score; pembilang=1; jumlah=0; do { printf("nPlease enter your test score %d:",pembilang); scanf("%f",&score); jumlah=score+jumlah; printf("njumlah is :%.2f",jumlah); pembilang++; } while(pembilang<=5); purata=(jumlah/5); printf("nnAverage test scores are is %.2f",purata); return 0; }
  • 20.  These loops are the loops which contain another looping statement in a single loop.  These types of loops are used to create matrix.  Any loop can contain a number of loop statements in itself.  If we are using loop within loop that is called nested loop.  In this the outer loop is used for counting rows and the internal loop is used for counting column
  • 21. #include<stdio.h> main() { int i,j; for(i=1;i<=5;i++) { for(j=1;j<=10;j++) { printf("*"); } printf("n"); } return 0; } output ********** ********** ********** ********** **********
  • 22.  The C language provides a capability that enables the user to define a set of ordered data items known as an array.  Suppose we had a set of grades that we wished to read into the computer and suppose we wished to perform some operations on these grades, we will quickly realize that we cannot perform such an operation until each and every grade has been entered since it would be quite a tedious task to declare each and every student grade as a variable especially since there may be a very large number.  In C we can define variable called grades, which represents not a single value of grade but a entire set of grades. Each element of the set can then be referenced by means of a number called as index number or subscript.
  • 23.  Like any other variable arrays must be declared before they are used. The general form of declaration is: type variable-name[size];  The type specifies the type of the elements that will be contained in the array, such as int float or char and the size indicates the maximum number of elements that can be stored inside the array for ex: float height[50]; int week[7];
  • 24.  The declaration int values[10]; would reserve enough space for an array called values that could hold up to 10 integers. Refer to the below given picture to conceptualize the reserved storage space. values[0] values[1] values[2] values[3] values[4] values[5] values[6] values[7] values[8] values[9]  The array values stored in the memory.
  • 25.  We can initialize the elements in the array in the same way as the ordinary variables when they are declared. The general form of initialization off arrays is: type array_name[size]={list of values};  The values in the list care separated by commas, for example the statement int number[3]={0,0,0};  Will declare the array size as a array of size 3 and will assign zero to each element if the number of values in the list is less than the number of elements, then only that many elements are initialized. The remaining elements will be set to zero automatically.  In the declaration of an array the size may be omitted, in such cases the compiler allocates enough space for all initialized elements. For example the statement int counter[]={1,1,1,1};  Will declare the array to contain four elements with initial values 1. this approach works fine as long as we initialize every element in the array.  The initialization of arrays in c suffers two draw backs 1. There is no convenient way to initialize only selected elements. 2. There is no shortcut method to initialize large number of elements.
  • 26. Arrays of Greater Dimension One-dimensional arrays are linear containers. © 2006 Pearson Addison-Wesley. 12.5.26 All rights reserved Multi-dimensional Arrays [0] [1] [2] [0] [0] [1] [2] [3] [1] [2] two-dimensional [0] [0] [1] [2] [3] [4] [1] [2] [3] [2] [1] [0] three-dimensional
  • 27. Initializing Multi-dimensional Arrays © 2006 Pearson Addison-Wesley. 12.5.27 All rights reserved [0] [0] [1] [2] [3] [1] [2] [0] [0] [1] [2] [3] [4] [1] [2] [3] [2] [1] [0] [0] [1] [2] declaration instantiation Oval[] circles; circles = new Oval[3]; double[][] table; table = new double[3][4]; int[][][] arr; arr = new int[4][5][3];
  • 28. How many cells in each of the following? double[][] distance = new double[10][15]; int[][][] cube = new int[8][8][10]; String[][][][][] words = new String[5][4][5][12][6]; © 2006 Pearson Addison-Wesley. 12.5.28 All rights reserved
  • 29. Creating Multi-dimensional Arrays The initialization notation for 1D arrays can be extended. char[][] words = { {'c', 'i', 'p', 'h', 'e', 'r'}, {'h', 'i', 'c', 'c’, 'u', 'p'}, {'a', 'p', 'i', 't', 'c', 'h'} }; © 2006 Pearson Addison-Wesley. 12.5.29 All rights reserved [0] [0] [1] [2] [3] [4] [5] [1] [2] c i p h e h i c c u a p i t c r p h Exercise How would you duplicate this behavior without the initialization notation?
  • 30. Processing Multi-dimensional Arrays The key to processing all cells of a multi-dimensional array is nested loops. 12.5.30 [0] [1] [2] [3] [0] [1] [2] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [3] [4] for (int row=0; row!=5; row++) { for (int col=0; col!=4; col++) { System.out.println( myArray[row][col] ); } } for (int col=0; col!=4; col++) { for (int row=0; row!=5; row++) { System.out.println( myArray[row][col] ); } } Exercises 1) Write a method to initialize this array with the given values. 2) Write a method to interchange two columns, indexed by two int parameters.
  • 31. Atlanta Chicago Dallas Los Angelas New York City Atlanta 0 722 2244 800 896 Chicago 722 0 1047 2113 831 Dallas 2244 1047 0 1425 1576 Los Angeles 800 2113 1425 0 2849 New York City 896 831 1576 2849 0 private final int[] mileage = {{0, 722, 2244, 800, 896}, {722, 0, 1047, 2113, 831}, {2244, 1047, 0, 1425, 1576}, {800, 2113, 1425, 0, 2849, {896, 831, 1576, 2849, 0} }; © 2006 Pearson Addison-Wesley. Tables 12.5.31 All rights reserved private final int atlanta = 0; private final int chicago = 1; private final int dallas = 2; private final int losAngelas = 3; private final int newYork = 4;
  • 32. #include<stdio.h> main( ) { int bil,data[10]={10,20,-5,36,-95,14,-82,0,1,25}; printf("Please select the value to be viewed [0-9]:"); scanf("%d",&bil); printf("nValue in data %d is %d",bil,data[bil]); return 0; } output Please select the value to be viewed [0-9]: 8 Value in data 8 is 1
  • 33. #include<stdio.h> main( ) { int data[50],saiz,kira_neg=0,kira_pos=0,count,bil; printf("Enter the size of the arrayn :"); scanf("%d",&saiz); for (count=0;count<saiz;count++) { for(count=0;count<saiz;count++) { bil=count+1; printf("nEnter the elements of the arrayn %d:",bil); scanf("%d",&data[count]); if(data[count]<0) kira_neg++; else kira_pos++; } } printf("nThere are %d positive numbers and %d negative numbers in the arrays",kira_pos,kira_neg); return 0; }