Pascal string

I need to write a program that shows the nth member of a string
A0=0
A1=1

An=A(n-2) + A(n-2)

HELPPP ANYBODY KNOW THIS...TANKS

Comments

  • Hi,
    I hope that this litle program will be useful:

    [code]
    program probe1;

    var mystr:string;
    var mystrpos:integer;
    var mypstr:pchar;

    BEGIN
    WriteLn('Please, enter a string:');
    ReadLn(mystr);
    for mystrpos := 0 to length(mystr) - 1 do
    begin
    mypstr := pchar(mystr);
    write(mypstr[mystrpos]);
    write(' ');
    end;
    END.
    [/code]

    It works on free pascal compiler.

    Please, forgive my possible errors.
  • Hi again,
    I have read your post once more. I do not know if I have had a translation problem. May be the answer that you searched is:
    [code]
    program succ;

    uses sysutils;

    var myind:Integer;
    var oldv:longint;
    var newv:longint;
    var valu:longint;
    var x:integer;
    var mystr:string;
    BEGIN
    oldv := 0;
    newv := 1;
    myind := 20;
    for x := 2 to myind do
    begin
    mystr := inttostr(x) + ': ' + inttostr(oldv) + ' + ' + inttostr(newv) + ' = ' ;
    valu := oldv + newv;
    oldv := newv;
    newv := valu;
    write(mystr);
    writeln(valu);
    end;
    END.
    [/code]

    I do not know which program can solve your problem.
    Please forgive my programming and translation errors.
  • : I need to write a program that shows the nth member of a string
    : A0=0
    : A1=1
    :
    : An=A(n-2) + A(n-2)
    :


    Not sure exactly what you want, but if you're talking about the [b]string[/b] type than you could simply use the indexing feature. Example:[code]var s:string;

    begin
    s:='abcdefghijklmnop...';
    writeln(s[4]); { <-- will return "d"; s[0] returns the length of a string in a char type}
    end.[/code]
Sign In or Register to comment.

Howdy, Stranger!

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

Categories