Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need a program

miladerfanianmiladerfanian Posts: 14Member
hi to all
I need a program in pascal to create this numbers with array.
this is my university project.
plz help me.

8 8 8 8 8 8
6 6 5 5 5 8
6 3 3 2 5 8
6 3 1 2 5 7
6 4 4 4 4 7
6 7 7 7 7 7

this is too important for me.
tnx alot
«1

Comments

  • AtexAtex Posts: 268Member
    : hi to all
    : I need a program in pascal to create this numbers with array.
    : this is my university project.
    : plz help me.
    :
    : 8 8 8 8 8 8
    : 6 6 5 5 5 8
    : 6 3 3 2 5 8
    : 6 3 1 2 5 7
    : 6 4 4 4 4 7
    : 6 7 7 7 7 7
    :
    : this is too important for me.
    : tnx alot
    :

    Do you need to compute this matrix and display it or just want to incorporate it in your code ? Be more specific.


  • miladerfanianmiladerfanian Posts: 14Member
    : Do you need to compute this matrix and display it or just want to
    : incorporate it in your code ? Be more specific.
    :
    :
    :


    I need just compute this matrix and display it.
    tnx.
  • AtexAtex Posts: 268Member
    : : Do you need to compute this matrix and display it or just want to
    : : incorporate it in your code ? Be more specific.
    : :
    : :
    : :
    :
    :
    : I need just compute this matrix and display it.
    : tnx.
    :

    OK, I need to know the initial data + the algorithm you want to apply
  • miladerfanianmiladerfanian Posts: 14Member

    : OK, I need to know the initial data + the algorithm you want to apply

    my problem is I don't have any algorithm for this.
    just I know that 1 repeat one time.2 repeat 2 time and ...

  • Phat NatPhat Nat Posts: 757Member
    :
    : : OK, I need to know the initial data + the algorithm you want to apply
    :
    : my problem is I don't have any algorithm for this.
    : just I know that 1 repeat one time.2 repeat 2 time and ...
    :
    :
    [code]
    13
    11 11 11 11 11 11 11 11 11 13
    11 9 8 8 8 8 8 8 11 13
    12 9 6 6 5 5 5 8 10 13
    12 9 6 3 3 2 5 8 10 13
    12 9 6 3 1 2 5 7 10 13
    12 9 6 4 4 4 4 7 10 13
    12 9 6 7 7 7 7 7 10 13
    12 9 9 9 10 10 10 10 10 13
    12 12 12 12 12 12 13 13 13 13
    [/code]

    (This isn't tested at all, just a thought)
    Couldn't you use an equation such as:
    [code]
    count := 0;
    For i := 1 to n do
    total := total + i;

    BoxWidth := Sqrt(Total);
    BoxHeight := Sqrt(Total);
    [/code]

    Basically you would add then lenths of all the numbers together (as if they were in a straight line). Also, we know that when wrapped up they will form a square and to find the Width/Length of a square from the area, we take the square root of the area, therefore giving us how long the sides will be.
    right??
    I could be way off in left field here, but this idea made sense in my messed up head. lol.

    In the example above, the numbers all add up to 91.
    The Sqrt(91) ~ 9.54
    Therefore, we expect it to have about 9 1/2 sides. As we can see it does have a square of 9x10 with a 0.04 leftover ;)
    Then we can just start drawing from there.

    Hope this helps.

    Phat Nat
  • AtexAtex Posts: 268Member
    :
    : : OK, I need to know the initial data + the algorithm you want to apply
    :
    : my problem is I don't have any algorithm for this.
    : just I know that 1 repeat one time.2 repeat 2 time and ...
    :
    :
    This would do... code could be optimized and documented more, I'm just too lazy today.... If you need more explanation just ask.

    [code][color=Blue]
    program matrix;

    uses crt; {<- for display}

    const _n_=9; {maximum value for n, can be higher but you have to rework the
    display part}
    type _matrix_=record
    el{ement}:word;
    tr{igger}:boolean; {true - change display direction}
    end;

    var no_of_elements:word;
    max_value:word;
    el:array[1..45] of _matrix_; {supports up to n=9 only}


    function calc_no_of_elements(n:word):word;
    { no_of_elements=1+2+3+4+5+...+n }
    begin
    calc_no_of_elements:=succ(n)*n div 2;
    end;

    procedure generate_matrix; {well, in a linear form only}
    {1,2,2,3,3,3,4,4,4,4,5,5,5,5,5....}
    var i,j,k:word;
    size,step:word;
    begin
    k:=1;
    for i:=1 to max_value do
    for j:=1 to i do begin
    el[k].el:=i;
    el[k].tr:=false;
    inc(k);
    end;
    step:=1;
    k:=1;
    size:=max_value;
    {1,1,2,2,3,3,4,4,5,5....}
    for i:=1 to size do begin
    inc(k,step);
    if k<=no_of_elements then el[k].tr:=true;
    inc(k,step);
    if k<=no_of_elements then el[k].tr:=true;
    inc(step);
    end;
    end;

    procedure display_matrix; {printing in spiral, works w/ singel digits only}
    var i:word;
    dir{ection}:byte; {1 - right, 2 -up, 3-left, 4-down}
    begin
    for i:=1 to 10 do writeln;{10 new lines}
    dir:=1; {initial direction}
    gotoxy(10,wherey-6); {positioning cursor}
    write(el[1].el); {print 1st element}
    gotoxy(wherex-1,wherey); {cursor goes under element}
    for i:=2 to no_of_elements do begin
    case dir of
    1:{right}begin gotoxy(wherex+1,wherey); {position cursor}
    write(el[i].el); {print element}
    gotoxy(pred(wherex),wherey); {cursor goes under element}
    end;
    2:{up }begin gotoxy(wherex,wherey-1); {position cursor}
    write(el[i].el); {print element}
    gotoxy(pred(wherex),wherey); {cursor goes under element}
    end;
    3:{left }begin gotoxy(wherex-1,wherey); {position cursor}
    write(el[i].el); {print element}
    gotoxy(pred(wherex),wherey); {cursor goes under element}
    end;
    4:{down }begin gotoxy(wherex,wherey+1); {position cursor}
    write(el[i].el); {print element}
    gotoxy(pred(wherex),wherey); {cursor goes under element}
    end;
    end;
    if el[i].tr then {direction trigger}
    if dir=4 then dir:=1 else inc(dir);
    end;
    gotoxy(1,wherey+6);
    writeln;
    end;


    begin
    clrscr;
    repeat
    write(#13#10,'Enter a value for N [1..',_n_,']: ');readln(max_value);
    no_of_elements:=calc_no_of_elements(max_value);
    until max_value in [1.._n_];
    generate_matrix;
    display_matrix;
    readkey; {wait for a key}
    end.
    [/color][/code]
  • miladerfanianmiladerfanian Posts: 14Member
    thank you bro.
    I write this in turbo pascal 7.0.
    compile has no error but when I run it and error shown:division by zero.
    can you help me about this?
  • AtexAtex Posts: 268Member
    : thank you bro.
    : I write this in turbo pascal 7.0.
    : compile has no error but when I run it and error shown:division by
    : zero.
    : can you help me about this?
    :

    Works fine with my TP7, but I got the patched crt unit. Try to run it under dosbox ( www.dosbox.com ), see what happens. I suspect is the crt unit what is responsible for this.
  • AtexAtex Posts: 268Member
    : thank you bro.
    : I write this in turbo pascal 7.0.
    : compile has no error but when I run it and error shown:division by
    : zero.
    : can you help me about this?
    :

    You can find the solution here:
    http://www.brain.uni-freiburg.de/~klaus/pascal/runerr200/
«1
Sign In or Register to comment.