Pascal Program to Read in Even Numbers Into An Array

Pascal Program to Read in Even Numbers Into An Array: This program takes in only even numbers into an array of two rows and two columns. 

Here, a looping and conditional statement are used, which are FOR DO and IF-THEN-ELSE respectively.

To begin.

An array is a collection of data of the same type and it consists of rows and columns. If you've solved matrices in mathematics, then you should have a good knowledge of Arrays in Pascal programming.

The FOR DO and IF-THEN-ELSE syntax in Pascal Programming is given by:


FOR (I=StartValue TO EndValue) DO

Statement(s)


IF (Condition) THEN

Statement(s);

ELSE

Statement(s);


Logic of the Program


Using both the looping and conditional statements in this Pascal Code example will allow us to make a selection of even numbers into an array with two rows and two columns.

Our Variable 'I' represents the rows while 'J' represents the columns, and with the modulus division operator in Mathematics, we can implement it here to ensure that any number divided by 2 without a remainder gives us our even two rows and columns.

You can also find the even numbers between a wide range of numbers by incrementing the looping END value for I and J variables.


Program Code


Program Eve;
Label 10;
Var
A : array[1..2,1..2] of integer;
I, j: integer;
Begin
For I:= 1 to 2 do
   For j:=  1 to 2 do
    Begin
10: readln (A[I , j]);
   If A[I , j] mod 2  < > 0 then goto 10
   Else
   End;
Begin
For I:= 1 to 2 do
For j:= 1 to 2 do
Writeln (A[I , j] );
Readln;
End.


Conclusion


The program above runs efficiently in printing even numbers into a 2 x 2 array.

Did this Pascal example code work for you or did you encounter problems while implementing it?

Let us know and we'll gladly help you out.


Also Read:

BASIC Program For Sum of Numbers Using IF Then Statement
Pascal Arithmetic Program Using IF THEN statement
Pascal Program to Create and Save Records in a Textfile
Pascal program To Calculate Area of a Triangle
Pascal Program of Matrix Multiplication
Pascal Program to Find The Average Of Only Positive Numbers Using While Do loop



Do you like this post? Please link back to this article by copying one of the codes below.

URL Of Post:


HTML Link Code:

BB (forum) link code:

Comments