Jump to content
🌙 COLDPLAY ANNOUNCE MOON MUSIC OUT OCTOBER 4TH 🎵

The Former Sara And Milica Thread


noonsun

Recommended Posts

  • Replies 103
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Ok, I gets it naow.

 

program pr4;

var a,b,c:integer;

begin

readln(a);

readln(b);

if a>b then c:=1

else c:=0;

writeln©;

readln;

end.

 

 

Never put a ; right before else, it won't wanna work. Also, you can left out the else part, if you don't need it. Like:

 

program pr5;

var a,b,c,:integer;

begin

readln(a);

readln(b);

if a<0 then a:=a*(-1);

c:=a+b;

writeln©;

readln;

end.

 

 

Variables don't have to be called by only one letter, you can call them abc or whatever if you want. Also, try deleting the last readln and run the program to see what happens.

Link to comment
Share on other sites

Oh, you...! :P

 

program pr6;

var n,i,x,s:integer;

begin

readln(n);

for i:=1 to n do

begin

readln(x);

s:=s+x;

end;

writeln(s);

readln;

end.

 

See the yellow part? Well, you can also type the program like this:

 

program pr6;

var n,i,x,s:integer;

begin

readln(n);

for i:=1 to n do

begin

readln(x);

s:=s+x;

end;

writeln(s);

readln;

end.

 

It doesn't matter.

 

Edit: forum fail. Consider the _ as a space.

 

program pr6;

var n,i,x,s:integer;

begin

readln(n);

for i:=1 to n do

_begin

__readln(x);

__s:=s+x;

_end;

writeln(s);

readln;

end.

Link to comment
Share on other sites

Okay. That makes sense, because with the space indents, you can, like... organize it better, visually. yeah.

 

edit: what does "for i:=1 to n do" mean? :huh:

 

edit two: also you typed your program wrong I think :P did you mean "s:=i+x;" instead of "s:=s+x;"?

Link to comment
Share on other sites

It's a loop that repeats n times. But you can put, for example,

 

for i:=2 to 5 do

s:=s+i;

 

 

I don't know if you noticed, but I put another begin and end in my previous post. If in a loop or under an if/else, or something other (I can't tell you everything now!), exists more than 1 command, you need an extra begin-end. That said, I don't need it in this post. But I could've put it, no harm will be done.

Link to comment
Share on other sites

Eh. My bad. I guess my brain is shut down by now. :lol:

 

program pr6;

var n,i,x,s:integer;

begin

readln(n);

s:=0;

for i:=1 to n do

begin

readln(x);

s:=s+x;

end;

writeln(s);

readln;

end.

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...