User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Pascal and Delphi section within the Software Development category of DaniWeb, a massive community of 427,488 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,404 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Pascal and Delphi advertiser: Programming Forums
Views: 7089 | Replies: 11
Reply
Join Date: Jan 2006
Location: Balkh
Posts: 67
Reputation: jamshid is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jamshid's Avatar
jamshid jamshid is offline Offline
Junior Poster in Training

Pascal Examples

  #1  
Jul 19th, 2006
Hi dear friends:
I am going to post some nice Pascal examples here , i hope it will be useful to you all. I hope you will also post here your good programes :

lets start :

1)

program operators;
uses crt;
begin
 clrscr;
 writeln(17 div 3);
 readln;
 writeln(7 mod 4);
 readln;
end.

2)

program posneg;
uses crt;
var 
 no : integer;
begin
 clrscr;
  Write('Enger a number:');
  readln(no);

  if (no > 0) then
   writeln('You enter Positive Number')
  else
    if (no < 0) then
     writeln('You enter Negative number')
    else
      if (no = 0) then
      writeln('You enter Zero');

  readln;
 end.

If you have any problem about the examples you can ask here,,, the next examples will come soon.
Impossible is Nothing
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2006
Posts: 59
Reputation: needs_help is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
needs_help's Avatar
needs_help needs_help is offline Offline
Junior Poster in Training

Re: Pascal Examples

  #2  
Dec 31st, 2006
{this makes a great deal of colors}
program lights;
uses crt;
var a,b:integer;
label 1;
begin
textbackground(white);
clrscr;
for a:=1 to 1000000 do inc b;
randomize;
1:
a:=random(4)+1;
if a=1 then textbackground(blue);
if a=2 then textbackground(red);
if a=3 then textbackground(green);
if a=4 then textbackground(yellow);
write(' ');
goto 1;
end.
Reply With Quote  
Join Date: Dec 2006
Posts: 59
Reputation: needs_help is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
needs_help's Avatar
needs_help needs_help is offline Offline
Junior Poster in Training

Re: Pascal Examples

  #3  
Jan 13th, 2007
{a random problem generator, test your math skills}
program learn;
uses crt;
var a,b,c,e,f,right: integer; d:real;
label 1,2,3,4,5;
begin
textbackground(green);
textcolor(white);
clrscr;
repeat
inc(f);
until f=100000;
randomize;
1:
e:=random(3)+1;
b:=random(200)+1;
c:=random(200)+1;
if e=1 then d:=b+c;
if e=2 then d:=b-c;
if e=3 then d:=b*c;
writeln('  ',b:3);
if e=1 then write('+ ');  
if e=2 then write('- ');
if e=3 then write('x ');
writeln(c:3);
writeln('______');
readln(a);
if a=d then
begin                                       
inc(right);
writeln('HORRAY! YOU GOT IT RIGHT! you have ',right,' points!');
end
else
begin
right:=right-1;
writeln('WRONG! you have ',right,' points');
end;
goto 1;
end.
Reply With Quote  
Join Date: Dec 2006
Posts: 59
Reputation: needs_help is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 2
needs_help's Avatar
needs_help needs_help is offline Offline
Junior Poster in Training

Re: Pascal Examples

  #4  
Jan 13th, 2007
Dig your heart out!
program veryweird;
uses crt;
type aaa=array[1..40,1..12] of char;
var a,b,c,d,e,pa,pd:integer; f:aaa; g:char;
label 1,2,3,4;
begin
pa:=1;
pd:=1;
writeln('hello');
writeln('press the arrow keys to move');
2:
IF KeyPressed THEN
BEGIN
g:=readkey;
CASE g OF
'H' :
begin
if pd=1 then goto 2; 
f[pa,pd]:='_';
pd:=pd-1;
f[pa,pd]:='@';
end;       
'K' :
begin
if pa=1 then goto 2;
f[pa,pd]:='_';
pa:=pa-1;
f[pa,pd]:='@';
end;
'M' :
begin
if pa=40 then goto 2;
f[pa,pd]:='_';
pa:=pa+1;
f[pa,pd]:='@';
end;
'P' :
begin
if pd=12 then goto 2;
f[pa,pd]:='_';
pd:=pd+1;
f[pa,pd]:='@';
end;
end;
clrscr;
for a:=1 to 12 do writeln(f[1,a],f[2,a],f[3,a],f[4,a],f[5,a],f[6,a],f[7,a],f[8,a],f[9,a],f[10,a],f[11,a],f[12,a],f[13,a],f[14,a],f[15,a],f[16,a],f[17,a],f[18,a],f[19,a],f[20,a],f[21,a],f[22,a],f[23,a],f[24,a],f[25,a],f[26,a],f[27,a],f[28,a],f[29,a],f[30,a],f[31,a],f[32,a],f[33,a],f[34,a],f[35,a],f[36,a],f[37,a],f[38,a],f[39,a],f[40,a]);
goto 2;
end
else goto 2;
end.
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,221
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 934
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: Pascal Examples

  #5  
Jan 14th, 2007
I'm sure you all worked very hard to write those little programs but I think they are quite useless to anyone without lots of comments that explain what the programs are doing. No one is going to wade through all that uncommented code and try to figure it out for themselves; not worth the time and effort.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Jan 2006
Location: Balkh
Posts: 67
Reputation: jamshid is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jamshid's Avatar
jamshid jamshid is offline Offline
Junior Poster in Training

Re: Pascal Examples

  #6  
Jan 24th, 2007
Thanks dear Ancient Dragon for your nice comment; you said that you work hard,, then if we work hard it means it has some benefits, either for us or for someone else..
Impossible is Nothing
Reply With Quote  
Join Date: Dec 2006
Location: Romania
Posts: 171
Reputation: radu84 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 16
radu84 radu84 is offline Offline
Junior Poster

Re: Pascal Examples

  #7  
Jan 25th, 2007
i'm not sure if i understand your last post.and also i think you haven't understand very well what the ancient wrote.

best regards,
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,221
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 934
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: Pascal Examples

  #8  
Jan 28th, 2007
Originally Posted by jamshid View Post
Thanks dear Ancient Dragon for your nice comment; you said that you work hard,, then if we work hard it means it has some benefits, either for us or for someone else..


Adding comments in your code can not be under-emphasized. Programs need comments that explain what it is doing. If readers do not know what the program is supposed to do then they will most likely not take the time to read and understand it. You yourself will forget within three months, I know because I've been there and done that. Comments become even more important than the code itself to improve code maintenance; at some future time someone other than yourself might have to change it. And if you get a job writing code you will be required by your employer to well-document your code.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation: jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough jwenting is a jewel in the rough 
Rep Power: 18
Solved Threads: 199
Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Pascal Examples

  #9  
Jan 28th, 2007
But don't overdo it.
Comments should tell you WHAT the code does, not HOW it does it.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote  
Join Date: Mar 2007
Posts: 14
Reputation: cigar is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
cigar cigar is offline Offline
Newbie Poster

Re: Pascal Examples

  #10  
Mar 29th, 2007
[quote=needs_help;295228]{this makes a great deal of colors}
[code]
program lights;
uses crt;
var a,b:integer;
label 1;
begin
textbackground(white);
clrscr;
for a:=1 to 1000000 do inc b;*
randomize;
1:
a:=random(4)+1;
if a=1 then textbackground(blue);
if a=2 then textbackground(red);
if a=3 then textbackground(green);
if a=4 then textbackground(yellow);
write(' ');
goto 1;
end.
where you find this * there is trouble. I will show you the error the program is telling me.
* Error 88 : "(" expected.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Pascal and Delphi Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Pascal and Delphi Forum

All times are GMT -4. The time now is 6:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC