Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

make table with 12 var in pascal

Status
Not open for further replies.

anthony68

Programmer
Sep 6, 2007
11
NL
i want to make a table with 12 var but do not know how to begin. Can you help me how my body needs
i want the output to look like this

1 2 3 4 5 6 7 8 etc

1 2 3 etc
2 3 4
3 etc
4
5
6
7
etc

then i want to find the values with combined are over 75 something like this
if var1+var2+var3>=75 then

en want the output of that procedure to look like this;

output;
var1+var6+var8>=75
var1+var5+var6>=75
var1+var4+var7>=75
var1+var8+var2>=75
var1+var7+var9>=75
 
Hi

As a first try... Your specification is not really clear, at least not to me.
Code:
[b]program[/b] greater_than_75;
  [b]const[/b] nr=12;
        limit=75;
  [b]var[/b] val:[b]array[/b][1..nr] [b]of[/b] Integer;
      i,j,e:Byte;
[b]begin[/b]
  [gray]{ you said nothing about the input... }[/gray]
  [b]for[/b] i:=1 [b]to[/b] nr [b]do[/b] [b]for[/b] j:=1 [b]to[/b] nr [b]do[/b] [b]for[/b] e:=1 [b]to[/b] nr [b]do[/b]
    [b]if[/b] (i<>j) [b]and[/b] (j<>e) [b]and[/b] (e<>i) [b]and[/b] (val[i]+val[j]+val[e]>=limit)
    [b]then[/b] WriteLn(val[i],[i]'+'[/i],val[j],[i]'+'[/i],val[e],[i]'>='[/i],limit);
[b]end[/b].

Feherke.
 
for the input it has to be integer from 0 to 150 thats the max and then in the table of the 12 vars the value in the table must seach after numbers greater then 75 or eacual.
so in the output of the program on screen;
must look like this ;

Var val1, val2,val3,val4,val5,valetc,
val1a, val2a,val3a,val4a,val5a,valetca,
val1b, val2b,val3b,val4b,val5b,valetcb,
val1c, val2c,val3c,val4c,val5c,valetcc: integer;

writeln (' ','70','71','72','73','74','75','etc');
writeln ('1',val1, val2,val3,val4,val5,valetc);
writeln ('2',val1a, val2a,val3a,val4a,val5a,valetca);
writeln ('3',val1b, val2b,val3b,val4b,val5b,valetcb);
writeln ('4',val1c, val2c,val3c,val4c,val5c,valetcc);


output screen look like this;

70 71 72 73 74 75 etc

1 71 72 73 etc
2 72 73 74
3 73 74 75
5 75 76
6
7
etc


Then i got to find out what value in the table is grater or ecual at 75. so something like this

program greater_than_75;
const nr=12;
limit=75;
var val:array[1..etc] of Integer;
i,j,e:Byte;
begin
{ you said nothing about the input... }
{input must look like this;}

var
r, c: Integer;
a: array [1..12,70..82] of Integer;

begin
for r := 70 to 82 do
for c := 1 to 12 do
Readln(a[r,c]);
end.

{ here i got to do something with the results of the readln (a[r,c]) I got to look in the values of the 2D array and take out the values that are grater or eceal as 75 }

for r:=70 to 82 do for c:=1 to 12 do for e:=1 to ??? do
if (r<>c) and (c<>r) and (e<>c) and (val[r]+val[c]+val[e]>=limit)
then WriteLn(val[r],'+',val[c],'+',val[e],'>=',limit);
end.

{ its comming to gether now but i do'n understand the basic of it}

 
At a glance, I think you can improve the for loops and cut out a lot of the if, simply by starting each for at the current value of the loop outside.

For a = 1 to limit do
begin
for b = a to limit do
begin
for c = b to limit do
begin
if (val[a]+val+val[c] > 75 then .....

The output will be different; the version above will find only one arrangement of each three variables that exceed 75, eg. var[1]+var[2]+var[3] and not also var[2]+var[1]+var[3] etc.

(there seems some ambiguity about > or >=)

If you had a big data set, you could improve the situation. For instance, you could check that the first, or the first two variables don't already exceed 75 before bothering to look at the third.
 
but i have to look at the third becouse val1+val4+val8>=75 and val12+val3+val6+val9>=75 that my goal.

the basic of the program is that any values no matter wich or how many are >=75 in the table
then the will form a group thats has >=75 those groups combined that i want to see
 
i want this out put in the pascal program i made with exel;
41 8 1 0 5 0 31 2 6 2 32 21
41 41 49 42 41 46 41 72 43 47 43 73 62
8 49 8 9 8 13 8 39 10 14 10 40 29
1 42 9 1 1 6 1 32 3 7 3 33 22
0 0 8 1 0 5 0 31 2 6 2 32 21
5 46 13 6 5 5 5 36 7 11 7 37 26
0 41 8 1 0 5 0 31 2 6 2 32 21
31 72 39 32 31 36 31 31 33 37 33 63 52
2 43 10 3 2 7 2 33 2 8 4 34 23
6 47 14 7 6 11 6 37 8 6 8 38 27
2 43 10 3 2 7 2 33 4 8 2 34 23
32 73 40 33 32 37 32 63 34 38 34 32 53
21 62 29 22 21 26 21 52 23 27 23 53 21

as you see the numbers in the x,y are x+y but i don't know how to begin..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top