SlideShare une entreprise Scribd logo
1  sur  12
Bahasa
Pemograman
Komputer (BPK) 2
Riki Afriansyah
Contents
Contents
What is a
Array?
Syntax of
Array
Two-
Dimensional
Arrays
Passing
Arrays to
Functions
What is a Array?
 An array is used to store a collection of data, but it is often more useful to think of an
array as a collection of variables of the same type.
 An array must be defined before it can be used to store information.
 An array definition specifies a variabel type and a name.
Syntax of Function
dataType arrayName[arraySize];
Example
C++ program to store and print 5 number entered by the user
using arrays.
Two-Dimensional Arrays
you can create an array of an array known as multi-dimensional array.
data_type array_name[x][y]; For example: int x[3][4];
Here, x is a two dimensional array. It can hold a maximum of 12 elements. You can think
this array as table with 3 rows and each row has 4 columns as shown below.
Two-Dimensional Arrays
#include <iostream>
using namespace std;
int main () {
// an array with 2 rows and 2 columns.
int a[2][2];
Int i,j;
// input each array element's value
for ( i = 0; i < 2; i++ )
for ( j = 0; j < 2; j++ ) {
cout << "a[" << i << "][" << j << "]: ";
cin>> a[i][j];
cout<< endl;
}
// output each array element's value
cout<< "PRINT" <<endl;
for ( i = 0; i < 2; i++ )
for ( j = 0; j < 2; j++ ) {
cout << "a[" << i << "][" << j << "]: ";
cout<<a[i][j]<< endl;
}
}
Passing Arrays to Functions
C program to pass an array containing age of person to a function. This function should
find average age and display the average age in main function.
#include <iostream>
#include <iomanip>
using namespace std;
float average(float age[]);
int main()
{
float avg, age[6];
cout<<"age:"<<endl;
for (int i=0;i<6;i++){
cin>>age[i];
}
avg = average(age); /* Only name of array is passed as
argument. */
cout<<"Average age="<<setprecision(2)<<avg;
}
float average(float age[])
{
int i;
float avg, sum = 0.0;
for (i = 0; i < 6; ++i) {
sum += age[i];
}
avg = (sum / 6);
return avg;
}
EXERCISES 1
Write a program that to store and print odd & even number entered
by the user (Storing 10 number entered by user in an array)
EXERCISES 2
Write a program using function and array that to store and print value of f(x) = x2+
3x + 1, then find the values. (Storing 5 number entered by user in an array)
EXERCISES 3
Write a program that calculates Two-Dimensional
Arrays (Add & Substract)
Array BPK 2

Contenu connexe

Tendances

Array in c language
Array in c languageArray in c language
Array in c languageumesh patil
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java languageHareem Naz
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional arrayRajendran
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayimtiazalijoono
 
Chapter12 array-single-dimension
Chapter12 array-single-dimensionChapter12 array-single-dimension
Chapter12 array-single-dimensionDeepak Singh
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in CSmit Parikh
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)Imdadul Himu
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2Rajendran
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysMaulen Bale
 

Tendances (20)

Array in C# 3.5
Array in C# 3.5Array in C# 3.5
Array in C# 3.5
 
Array in c
Array in cArray in c
Array in c
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Array in c
Array in cArray in c
Array in c
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Chapter12 array-single-dimension
Chapter12 array-single-dimensionChapter12 array-single-dimension
Chapter12 array-single-dimension
 
Array lecture
Array lectureArray lecture
Array lecture
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Array in-c
Array in-cArray in-c
Array in-c
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 
Array in C
Array in CArray in C
Array in C
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
Arrays
ArraysArrays
Arrays
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 

Similaire à Array BPK 2

Similaire à Array BPK 2 (20)

Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Array
ArrayArray
Array
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Fp201 unit4
Fp201 unit4Fp201 unit4
Fp201 unit4
 
Intro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technologyIntro to C# - part 2.pptx emerging technology
Intro to C# - part 2.pptx emerging technology
 
SP-First-Lecture.ppt
SP-First-Lecture.pptSP-First-Lecture.ppt
SP-First-Lecture.ppt
 
Array assignment
Array assignmentArray assignment
Array assignment
 
Arrays
ArraysArrays
Arrays
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
Array and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptxArray and string in C++_093547 analysis.pptx
Array and string in C++_093547 analysis.pptx
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Arrays and strings in c++
Arrays and strings in c++Arrays and strings in c++
Arrays and strings in c++
 
Chapter1.pptx
Chapter1.pptxChapter1.pptx
Chapter1.pptx
 
2DArrays.ppt
2DArrays.ppt2DArrays.ppt
2DArrays.ppt
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
2D Array
2D Array 2D Array
2D Array
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 

Plus de Riki Afriansyah

Latar belakang industri dan perdagangan
Latar belakang industri dan perdaganganLatar belakang industri dan perdagangan
Latar belakang industri dan perdaganganRiki Afriansyah
 
Pendahuluan Sistem E-Persuratan
Pendahuluan Sistem E-PersuratanPendahuluan Sistem E-Persuratan
Pendahuluan Sistem E-PersuratanRiki Afriansyah
 
Modul 3 Cara Membuat View Pada CodeIgniter
Modul 3 Cara Membuat View Pada CodeIgniterModul 3 Cara Membuat View Pada CodeIgniter
Modul 3 Cara Membuat View Pada CodeIgniterRiki Afriansyah
 
Modul 2 Cara Membuat Controller Pada CodeIgniter
Modul 2 Cara Membuat Controller Pada CodeIgniterModul 2 Cara Membuat Controller Pada CodeIgniter
Modul 2 Cara Membuat Controller Pada CodeIgniterRiki Afriansyah
 
Modul1 Penjelasan Mengenai Codeigniter
Modul1 Penjelasan Mengenai CodeigniterModul1 Penjelasan Mengenai Codeigniter
Modul1 Penjelasan Mengenai CodeigniterRiki Afriansyah
 

Plus de Riki Afriansyah (9)

Function BPK2
Function BPK2Function BPK2
Function BPK2
 
Database
DatabaseDatabase
Database
 
Latar belakang industri dan perdagangan
Latar belakang industri dan perdaganganLatar belakang industri dan perdagangan
Latar belakang industri dan perdagangan
 
Pendahuluan Sistem E-Persuratan
Pendahuluan Sistem E-PersuratanPendahuluan Sistem E-Persuratan
Pendahuluan Sistem E-Persuratan
 
Modul 6 Perulangan
Modul 6 PerulanganModul 6 Perulangan
Modul 6 Perulangan
 
Modul 5 Kondisional
Modul 5 KondisionalModul 5 Kondisional
Modul 5 Kondisional
 
Modul 3 Cara Membuat View Pada CodeIgniter
Modul 3 Cara Membuat View Pada CodeIgniterModul 3 Cara Membuat View Pada CodeIgniter
Modul 3 Cara Membuat View Pada CodeIgniter
 
Modul 2 Cara Membuat Controller Pada CodeIgniter
Modul 2 Cara Membuat Controller Pada CodeIgniterModul 2 Cara Membuat Controller Pada CodeIgniter
Modul 2 Cara Membuat Controller Pada CodeIgniter
 
Modul1 Penjelasan Mengenai Codeigniter
Modul1 Penjelasan Mengenai CodeigniterModul1 Penjelasan Mengenai Codeigniter
Modul1 Penjelasan Mengenai Codeigniter
 

Dernier

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
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
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Dernier (20)

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Array BPK 2

  • 2. Contents Contents What is a Array? Syntax of Array Two- Dimensional Arrays Passing Arrays to Functions
  • 3. What is a Array?  An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.  An array must be defined before it can be used to store information.  An array definition specifies a variabel type and a name.
  • 4. Syntax of Function dataType arrayName[arraySize];
  • 5. Example C++ program to store and print 5 number entered by the user using arrays.
  • 6. Two-Dimensional Arrays you can create an array of an array known as multi-dimensional array. data_type array_name[x][y]; For example: int x[3][4]; Here, x is a two dimensional array. It can hold a maximum of 12 elements. You can think this array as table with 3 rows and each row has 4 columns as shown below.
  • 7. Two-Dimensional Arrays #include <iostream> using namespace std; int main () { // an array with 2 rows and 2 columns. int a[2][2]; Int i,j; // input each array element's value for ( i = 0; i < 2; i++ ) for ( j = 0; j < 2; j++ ) { cout << "a[" << i << "][" << j << "]: "; cin>> a[i][j]; cout<< endl; } // output each array element's value cout<< "PRINT" <<endl; for ( i = 0; i < 2; i++ ) for ( j = 0; j < 2; j++ ) { cout << "a[" << i << "][" << j << "]: "; cout<<a[i][j]<< endl; } }
  • 8. Passing Arrays to Functions C program to pass an array containing age of person to a function. This function should find average age and display the average age in main function. #include <iostream> #include <iomanip> using namespace std; float average(float age[]); int main() { float avg, age[6]; cout<<"age:"<<endl; for (int i=0;i<6;i++){ cin>>age[i]; } avg = average(age); /* Only name of array is passed as argument. */ cout<<"Average age="<<setprecision(2)<<avg; } float average(float age[]) { int i; float avg, sum = 0.0; for (i = 0; i < 6; ++i) { sum += age[i]; } avg = (sum / 6); return avg; }
  • 9. EXERCISES 1 Write a program that to store and print odd & even number entered by the user (Storing 10 number entered by user in an array)
  • 10. EXERCISES 2 Write a program using function and array that to store and print value of f(x) = x2+ 3x + 1, then find the values. (Storing 5 number entered by user in an array)
  • 11. EXERCISES 3 Write a program that calculates Two-Dimensional Arrays (Add & Substract)