Find Out the summation Of the boundary elements Of the array

Problem 2.8:

Given a two-dimensional array, find out the summation of the boundary elements of the array. Here no element should be added twice. Solution: >>First, we have to identify the boundary elements.

In a two dimensional array, elements of first column and the last column and the first row and last row are the boundary elements as shown in the Figure-2.8.

>> Here the index, i represents the row number and j represents the column-number.

When i is 1, the row is the first row and when i is m (where m represents the number of rows in the array), the row is the last row.

Similarly, when j = 1, the column is the first column and the index of the last column is j = n. So, a number in a two-dimensional array is a boundary element if i = 1, i = m, j = 1 or j = n

The summation Of the boundary elements Of the array

We shall start from the first number of the array.

If it is a boundary element, the number will be added to the sum (which is a variable to store the result and initially it is set zero).

We shall check every number whether it is a boundary element or not, if the number is a boundary element it will be added to sum.

Otherwise, we shall proceed with the next number of the list (array) and continue the process to the end of the list.

Location of an element of a two-dimensional array Row-major Order:

If Loc (A[i, j]) denotes the location in the memory of the element A[i][j] or Aij, then in row-major order –

Loc (A[i, j]) = Base (A) + (n (i - 1) + (j - 1)) * w;

Here Base (A) is starting or base address of the array A, n is the number of columns and w is the width of each cell, i.e, number bytes per cell.

Column-major Order:

In column-major order,

Loc (A[i, j]) = Base (A) + (m (j - 1) + (i - 1)) * w;

Here Base (A) is starting or base address of the array A, m is the number of rows and w is the cell width

Example: Base address, Base (A) = 100, Size of the array = 5 × 6. If the type of array is integer then find Loc (A[4, 3]). Solution: (2 bytes for each integer cell in C/C++) If the array is stored in row-major order: Loc (A[4, 3]) = Base (A) + (n (i - 1) + (j - 1))* 2 = 100 + (6 × 3 + 2)* 2 = 100 + 40 = 140

If the array is stored in memory in column-major order: Loc (A[4, 3]) = Base (A) + m (j - 1) + (i - 1)* 2 = 100 + (5 × 2 + 3)* 2 = 100 + 26 =126

This complexity is related to execution time of the algorithm. It depends on the number of element (item) comparisons and number of element movement (movement of data from one place to another). However, the complexity of the most of the algorithms described here related to the number of element comparisons. That means, the complexity of the algorithm is computed with respect to the total number of element (item) comparisons needed for the algorithm

Computer science as well as computer engineering deals with two jargons which are software and hardware.

Without software, hardware (electrical, mechanical, electronic parts of computer that we see and touch) is useless.

So, study of software is very important in computer science, and software consists of programs which use different types of data.

In a program we not only use elementary data items but also use different types of organized data. That means we use data structure in a program. As we know we write programs to solve problems. That is, to solve problems we have to use data structures. The different data structures give us different types of facilities.

If we need to store data in such a way that we have to retrieve data directly irrespective of their storage location. We can get this facility using one type of data structure such as array gives us such facility.

Sequence of instructions of any programming language that can be followed to perform a particular task.

For a particular problem, at first we may write an algorithm then the algorithm may be converted into a program.

In a program usually we use a large amount of data. Most of the cases these data are not elementary items, where exists structural relationship between elementary data items.

Set or sequence of instructions (steps) that can be followed to perform a task (problem).
Do not strictly follow grammar of any particular programming language.
However its language may be near to a programming language.

qEach and every algorithm can be divided into three sections.

vFirst section is inputsection, where we show which data elements are to be given.

vThe second section is very important one, which is operational or processing section. Here we have to do all necessary operations, such as computation, taking decision, calling other procedure (algorithm) etc.

vThe third section is output, where we display the result found from the second section

Example of Data Structures: Array, Linked List, Stack, Queue, Tree, Graph, Hash Table etc. Types of elementary data item: Character, Integer, Floating point numbers etc.

Expressions of elementary data in C/C++ Elementary data item - Expression in C/C++ Character - char Integer - int Floating point number - float

Elementary items constitute a unit and that unit may be considered as a structure. .>> structure may be treated as a frame or proforma where we organize some elementary items in different ways. Data structure is a structure or unit where we organize elementary data items in different ways. >>That means, a data structure is a means of structural relationships of elementary data items for storing and retrieving data in computer’s memory. Usually elementary data items are the elements of a data structure. However, a data structure may be an element of another data structure. That means a data structure may contain another data structure

printf(" Welcome.
C programmer is sample source code search engine. Do you need sample source code ? Do you search program code ? Do you want find example code ? Do you want learning coding ? Everything is here. You can get code. You can search code, application sample, code project. Various programming languages code examples, sample source codes is here. This Site also Provide Help C/c++ Language Developed. ")

If need to be any Kind of email Us
cprogrammerbd@gmail.com.

#include stdio
#include conio
int main()
{
int i,j,n;
printf("Enter Number Of Terms:");
scanf("%d",&n);
printf("Prime Numbers Are Follwing ");
for(i=2;i<=n;i++) { for(j=2;j<=i;j++) { if(i%j==0) break; } if(i==j) printf("%d",i); } return 0; } Any more about prime number