Need help with my program, read from a text into many variables. - Programmers Heaven

Howdy, Stranger!

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


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 help with my program, read from a text into many variables.

marylyrmarylyr Posts: 1Member

Hello, i have to make this program, but i still haven't finished it and i need some help. This is what i have to do. Make a program in Pascal that after has read a text with a list of nums., it will return the numb. of the nums that appear less than one times in the text.

The text that will be read from the program should be like that.

In the first line there are two nums. seperated by a space, n and m. N is the number of nums that exist, like if the text contains the numbers 1,2,3,4, n is 4 (1..n). M is how many lines follow. Every line has a couple of nums, a,b, (1=<a=<n), (1=<b=<n) (a<>b) a and b are separated by a space.

The file that the program will make will have written on it a num., that says how many nyms are appeared less than two tims in the text.

All the nums. are Integer.


i've made the following program, but it only reads the first line of the text. Anyone that can help me? The deadline is almost ended. Thanks in advance. My code is the following. Program thefinalp;

Uses SysUtils;

Var f:Text; m,d:Integer; n:Char; c:String[1];

a,e:array of integer; LowArr:Integer; HighArr:Integer; ArrayLen:Integer; i:Integer;

begin Assign(f,'finalp.txt'); Reset(f);

repeat Read (f,n); Write(n); until (n=' ');

Read(f,c); Write(c);

while not SeekEoln(f) do begin read(f,d); Write(d); End; Readln; Writeln;


setlength(a,m); LowArr:=Low(a); HighArr:=High(a); ArrayLen:=Length(a);

setlength(e,m); LowArr:=Low(e); HighArr:=High(e); ArrayLen:=Length(e);

for i:= LowArr to HighArr do


repeat Read (f,a[i]); Write(a[i]); until (n=' ');

Read(f,c); Write(c);

while not SeekEoln(f) do begin read(f,e[i]); Write(e[i]); End; Readln; Writeln;

End; Readln; End.

I've made the code after that, the program is how to put into variables all the nums. I'm a beginner so if anyone could give me an example, would help a lot. domes.out 6 7 2 2 4 4 1 3 5 4 3 1 3



  • StupidKidStupidKid VietnamPosts: 7Member

    ough I can't check on a computer right now but maybe you can use an array 'A' to know how many times a number appears. And I don't know the limit of the numbers so you should use Longint for all vars

    For i:=1 to m do
    For i:=1 to n do
      If a[i]>=2 then inc(count);
    Fillchar({array's name},{size of array},{value}); used to set value for all the array. Count is the answer you need. Maybe it's too late now :(
  • StupidKidStupidKid VietnamPosts: 7Member

    Oh you should also put in one more line : count:=0; after line 11

Sign In or Register to comment.