Arrays of Two-Dimensions

Slides:



Advertisements
Similar presentations
Revision.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
1 Arrays Chapter 9. 2 Outline  The array structure (Section 9.1)  Array declaration  Array initialization  Array subscripts  Sequential access to.
Introduction to Functions Programming. COMP102 Prog Fundamentals I: Introduction to Functions /Slide 2 Introduction to Functions l A complex problem is.
TK1914: C++ Programming Array II. Objective In this chapter you will explore how to manipulate data in a two-dimensional array. 2FTSM :: TK1914,
CS Sept Your first C++ program… Boilerplate // Cannon, demo program #include using namespace std; int main() {// program goes here… return.
Arrays Programming COMP102 Prog. Fundamentals I: Arrays / Slide 2 Arrays l An array is a collection of data elements that are of the same type (e.g.,
More on Functions Programming. COMP104 Lecture 19 / Slide 2 Passing Parameters by Reference l To have a function with multiple outputs, we have to use.
#include using namespace std; void main() { int a[3]={10,11,23}; for(int i=0;i
Chapter 4 Summation.
CSE202: Lecture 16The Ohio State University1 Two Dimensional Arrays.
Pass by Reference. COMP104 Pass by Reference / Slide 2 Passing Parameters by Reference * To have a function with multiple outputs, we have to use pass.
Programming is instructing a computer to perform a task for you with the help of a programming language.
Prepared by MURLI MANOHAR PGT (COMPUTER SCIENCE) KV,B.E.G., PUNE.
CS1201: Programming Language 2 Recursion By: Nouf Almunyif.
Current Assignments Homework 3 is due tonight. Iteration and basic functions. Exam 1 on Monday.
Looping II (for statement). CSCE 1062 Outline  for statement  Nested loops  Compound assignment operators  Increment and decrement operators.
First steps Jordi Cortadella Department of Computer Science.
Two-Dimensional Arrays ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Objective: Students will be able to: Declare and use variables Input integers.
Modular Programming – User Defined Functions. CSCE 1062 Outline  Modular programming – user defined functions  Value returning functions  return statement.
Introduction to Functions.  A complex problem is often easier to solve by dividing it into several smaller parts, each of which can be solved by itself.
Think First, Code Second Understand the problem Work out step by step procedure for solving the problem (algorithm) top down design and stepwise refinement.
Module 1: Array ITEI222 - Advance Programming Language.
Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the.
Computer Skills2 / Scientific Colleges 1 Arrays Topics to cover: Arrays Data Types One-dimensional Arrays Two-dimensional Arrays.
Looping I (while statement). CSCE 1062 Outline  Looping/repetition construct  while statement (section 5.1)
Review 1.
Lecture 11 Multi-dimensional Arrays
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Two-Dimensional Arrays
2-D Array.
Two Dimensional Array Mr. Jacobs.
Two-Dimensional Arrays Lesson xx
Engineering Problem Solving with C++, Etter
Programming fundamentals 2 Chapter 1:Array
Multi-dimensional Array
C++ Arrays.
לולאות קרן כליף.
Lecture 8 – 9 Arrays with in a class
Dynamic Memory Allocation Reference Variables
Function Basics.
Programming -2 برمجة -2 المحاضرة-5 Lecture-5.
Array Data Structure Chapter 6
Array Data Structure B.Ramamurthy 11/21/2018 B.Ramamurthy.
CS1201: Programming Language 2
Data type List Definition:
CS150 Introduction to Computer Science 1
הרצאה 03 אבני היסוד של תוכנית ב- C
Counting Loops.
Starting Out with C++: From Control Structures through Objects
Pointers & Functions.
File Review Declare the File Stream Object Name
Multidimensional Arrays
Pass by Reference.
File Processing in C++ Data is stored in files so that it may be retrieved for processing when needed.
Arrays Topics to cover: Arrays Data Types One-dimensional Arrays
CS1201: Programming Language 2
CS1201: Programming Language 2
CHAPTER 2 Arrays and Vectors.
Statements and flow control
Arrays Arrays A few types Structures of related data items
CHAPTER 2 Arrays and Vectors.
Pointers and dynamic objects
Pointers & Functions.
Introduction to Functions
CS31 Discussion 1D Winter19: week 4
Programming Strings.
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
Dr. Khizar Hayat Associate Prof. of Computer Science
Presentation transcript:

Arrays of Two-Dimensions Syntax ( in Algorithm ): Syntax ( in C++ ): Array aname [nrows] [ncolumns] of atype Example: //declaring array B of 2 rows and 3 columns Array B [2] [3] of type integer atype aname [nrows] [ncolumns] ; int B [2] [3] ; Array in diagram:

Arrays of Two-Dimensions Reading array of two-dimensions: Syntax ( in Algorithm ): Syntax ( in C++ ): Array B [2] [3] of type integer for ( i  1 to 2 by 1 ) do for ( j  1 to 3 by 1 ) do input B[i][j] End for int B [2] [3] ; int i , j ; for ( i = 0 ; i < 2 ; i++ ) for ( j = 0 ; j < 3 ; j++ ) cin >> B[ i ] [ j ] ;

Example1 Write algorithm and a C++ program that reads array A of size (2 x 3) and finds the sum of the elements in each column. Algorithm sum_columns begin Array B[2][3] of type integer output "Enter 6 array elements: " for ( i 1 to 2 by 1 ) do for ( j1 to 3 by 1)do input B[i][j] End for End for // Process the array now clmsum  clmsum + B[i][j] output " sum of column no. " , j , " is " , clmsum clmsum  0 End sum_columns 3

Example1 #include <iostream> void main ( ) using namespace std; void main ( ) { int i, j , clmsum = 0 ; int B[2][3]; cout << "Enter 6 array elements: " ; for ( i = 0 ; i < 2 ; i++ ) for ( j = 0 ; j < 3 ; j++) cin >> B[i][j] ; // Process the array now { clmsum = clmsum + B[i][j] ; cout << " sum of column no. " << j << " is " << clmsum<<endl; clmsum = 0; }

Example2 of Two-Dimensional Array Write algorithm and a C++ program that reads an array of size (3 x 3) and finds the product of the diagonal elements.

Example2(Algorithm) Algorith Product_D_E Begin Array B[3][3] of type integer product  1 output "Enter the 9 array elements: " for ( i  1 to 3 by 1 ) do for ( j  1 to 3 by 1 ) do input B[i][j] End for // Process the array now if ( i = j ) then product  product * B[i][j] End if output " The product of the diagonal elements = " , product End Product_D_E

Example2(C++) #include <iostream> Using namespace std; void main ( ) { int i, j , product = 1 ; int B[3][3]; cout << "Enter the 9 array elements: " ; for ( i = 0 ; i <3 ; i++ ) for ( j = 0 ; j < 3 ; j++) cin >> B[i][j] ; // Process the array now for ( i = 0 ; i < 3 ; i++) for ( j = 0 ; j < 3 ; j++ ) if ( i == j ) product = product * B[i][j] ; cout << " The product of the diagonal elements = " << product << endl; }