|
AUDIO
COMPUTERS
NETWORKS
PDAs
SUPPLIES
TELEVISIONS
WIRELESS
ARTICLES
HARDWARE
SOFTWARE
PROGRAMMING
WEBMARKETING
WIRELESS

FREELANCING
VIRTUALeOFFICES
TRADELINKS
GEMINISOFTWARE
|

_________________________________________________________________________________________

___________________
Welcome
to our website
{$P256,G256,B-}
{ THIS PASCAL PROGRAM READS IN THE ORDER OF A TWO DIMENSIONAL ARRAY }
{ AND THEN FILLS THE SQUARE MATRIX WITH THE GIVEN DATA. }
{ THEN THIS PROGRAM CHECKS TO SEE IF THE SUM OF ALL THE ROWS }
{ AND COLUMNS ADD UP TO MAKE A MAGIC SQUARE. }
program magic_square(input,output,infile,outfile);
const maxrow = 22;
maxcol = 18;
type list = array[1..maxrow,1..maxcol] of integer;
var numlist : list;
i,count : integer;
infile,outfile : text;
{***************************************************************}
{ THIS PROCEDURE TURNS THE PAGE ON THE PRINTER USING chr(12). }
procedure page(var otfil : text);
begin
write(otfil,chr(12));
end;
{***************************************************************}
{ THIS PROCEDURE TESTS FOR THE MAGIC SQUARE. }
procedure magic(size,sum : integer; var outfil : text;
var void : boolean);
var mgc : boolean;
mgcnum : integer;
begin
void := true;
mgcnum := (1 + size * size ) * size div 2;
if sum = mgcnum then
mgc := true
else mgc := false;
if not mgc then
void := false
END;
{***************************************************************}
{ THIS PROCEDURE ADDS UP ALL THE ROWS IN THE MATRIX. }
procedure row_sum(lim : integer; var rsm : integer;
var table : list;
var outfl : text);
var rw,col : integer;
mgcnum,magsqr : boolean;
begin
mgcnum := true;
for rw := 1 to lim do begin
rsm := 0;
for col := 1 to lim do
rsm := rsm + table[rw,col];
magic(lim,rsm,outfl,mgcnum);
if not mgcnum then
magsqr := false;
end;
if magsqr then
begin
writeln(outfl,' EACH ROW AND COLUMN EQUALS ',rsm);
writeln(outfl,' THIS IS A MAGIC SQUARE!');
end;
end;
{**************************************************************}
{ THIS PROCEDURE ADDS UP ALL THE COLUMNS IN THE MATRIX. }
procedure col_sum(lim : integer; var csm : integer;
var table : list;
var outfl : text);
var rw,clmn : integer;
begin
for clmn := 1 to lim do begin
csm := 0;
for rw := 1 to lim do
csm := csm + table[rw,clmn];
end;
end;
{***************************************************************}
{ THIS PROCEDURE WRITES OUT THE ARRAY AND DRAWS THE BOXES. }
procedure rite_file(var tfil : text; var nlst : list;
count : integer);
var row,column,chek,rsum,csum : integer;
{----------------------------------------------------------}
{ This procedure draws the horizontal lines. }
procedure drawhoriz(var fil : text; num : integer);
const draw = '+----';
var i : integer;
begin
for i := 1 to num do
write(fil,draw);
writeln(fil,'+');
end;
{----------------------------------------------------------}
{ This procedure draws the vertical lines. }
procedure drawvert(var fil : text; chk : integer);
begin
if chk < 10 then
write(fil,' | ')
else
write(fil,' | ')
end;
{----------------------------------------------------------}
begin
drawhoriz(tfil,count);
rsum := 0;
csum := 0;
for row := 1 to count do begin
write(tfil,'| ');
for column := 1 to count do begin
write(tfil,nlst[row,column]);
chek := nlst[row,column];
drawvert(tfil,chek)
end;
writeln(tfil);
drawhoriz(tfil,count);
end;
writeln(tfil);
row_sum(count,rsum,nlst,tfil);
col_sum(count,csum,nlst,tfil);
end;
{***************************************************************}
{ THIS PROCEDURE STORES THE DATA IN THE MATRIX. }
procedure read_file(var nfil : text; var nmlst : list;
var otfil : text);
var lcv,row,column,number : integer;
begin
readln(nfil,lcv);
for row := 1 to lcv do
for column := 1 to lcv do
begin
read(nfil,number);
nmlst[row,column] := number;
end;
readln(nfil);
rite_file(otfil,nmlst,lcv);
end;
{***************************************************************}
begin { MAIN }
assign(infile,'LAB10.DAT');
reset(infile);
assign(outfile,'PRN');
rewrite(outfile);
while not eof(infile) do begin
read_file(infile,numlist,outfile);
page(outfile);
end;
close(infile);
close(outfile);
end.
DATAFILE:
LAB10.DAT
3
3 5 7
4 9 2
8 1 6
5
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 12 9
17 24 1 8 15
3
3 5 7
4 9 2
8 1 4
7
38 47 7 9 18 27 29
46 6 8 17 26 35 37
5 14 16 25 34 36 45
13 15 24 33 42 44 4
21 23 32 41 43 3 12
22 31 40 49 2 11 20
30 39 48 1 10 19 28
_________________________________________________________________________________________
About
Us
Content
provided by VirtualeCorporation
GeminiSoftwareSystems
GeminiMalls GeminiMagazine
TradeLinks
VirtualeCatalog
VirtualeCorporation
VirtualeDirectory
VirtualeJobs VirtualeMedia
VirtualeOffices
_______________________________________________________________________________________
Give to Charities Click
Here!
Michael J. Fox Parkinson's Website Click
Here!
__________________________________________
Software
including hosting, websites, graphics, development, office, security..Click
Here!
________________________________________________________________________________________

Buy Online at Autodesk
"Internet Security Systems' BlackICE Protection Products"
Need to create a business plan now? Get OfficeReady Business Plans
Kaspersky Anti-Virus Products
Free Shipping when you spend $100 on Macromedia.com
Convert paper and PDF into Documents you can edit, share and archive - Buy OmniPage Pro from ScanSoft.
Broderbund Bargain Bin - All Titles Under $9.99! Plus FREE shipping with orders over $20!
_____________________

|