Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 19:41

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Need Help on one PASCAL program (it's easy)

Discussion on Need Help on one PASCAL program (it's easy) within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
obeliskk1's Avatar
 
elite*gold: 0
Join Date: Mar 2014
Posts: 346
Received Thanks: 4
Need Help on one PASCAL program (it's easy)

Ok, i need help about this code. I need someone to calculate value of "k" after each possible loop. The last value of k is 51, but i can't seem to get that value by calculating it by myself. Can anyone help me where i am going wrong?
I need also an explanation how u get to that number, so i can understand in future tasks.


Code:
Program a;
var
  i, j, k, m, n, p, r: integer;
begin
  k:=1;
  p:=1;
  r:=3;
  n:=1;
  j:=1;
repeat
  k:=2*(n+sqr(j-2))+k;
  j:=j+2;
until j>=5;
 
for i:= r downto p do
  if i <> 2 then
  begin
      for m:=1 to 2 do
        k:= k+3*m;
        k:= p mod i + k;
  end
  else
  begin
      for m:=1 to 2 do
        k:=2*k +m;
        k:=k div i + 2;
  end;
writeln(k);
end.
obeliskk1 is offline  
Old 06/25/2016, 19:49   #2
 
elite*gold: 0
Join Date: May 2010
Posts: 86
Received Thanks: 27
Quote:
Originally Posted by obeliskk1 View Post
Can anyone help me where i am going wrong?
Not really. It looks like homework apparently.

So what's the problem exactly? You have problems understanding the whole code or just parts? Which parts? I would suggest to use a table and keep record of all variables while going through the algorithm line by line. Thats what i usually do when i have problems understanding (most iterative) algorithms.

I suggest to post your progress so far so we can actually take a look and see where your problem is.

[I still do not understand why you flag your question as "it's easy" although you have problems understanding it ]
Dungedragon is offline  
Old 06/25/2016, 20:01   #3
 
obeliskk1's Avatar
 
elite*gold: 0
Join Date: Mar 2014
Posts: 346
Received Thanks: 4
Quote:
Originally Posted by Dungedragon View Post
Not really. It looks like homework apparently.

So what's the problem exactly? You have problems understanding the whole code or just parts? Which parts? I would suggest to use a table and keep record of all variables while going through the algorithm line by line. Thats what i usually do when i have problems understanding (most iterative) algorithms.

I suggest to post your progress so far so we can actually take a look and see where your problem is.

[I still do not understand why you flag your question as "it's easy" although you have problems understanding it ]
I thought it was super easy for someone who is doing these kind of stuff, since i'm not even beginner.

Ok, here is the thing, in the first FOR loop i have to do that loop 3 times (3 to 1). And i got from compiler results: 19 (i=3), 42 (i=2), 51 (i=1).

To get those results, i had to do next FOR loop, which consisted of 2 "k" equations and also i'm doing it 2 times since it 1 to 2 loop.
But in order to get correct result in second time doing that loop, i am not suppose to calculate the second "k" equation. Does anyone know why?

ALSO not that this is not homework, this just a random code i took to practise on understanding for loop when it becomes little bit messy.
obeliskk1 is offline  
Old 06/25/2016, 20:36   #4
 
.Scy's Avatar
 
elite*gold: 15
Join Date: Jul 2010
Posts: 3,926
Received Thanks: 1,158
how about just putting a writeln(k) in each of the loops with a text that says where you are? example:
Code:
program a;
var
i, j, k, m, n, p, r: integer;
begin
k:=1;
p:=1;
r:=3;
n:=1;
j:=1;
repeat
k:=2*(n+sqr(j-2))+k; writeln("every value that changes");
j:=j+2;
until j>=5;
for i:= r downto p do
if i <> 2 then
begin
for m:=1 to 2 do
k:= k+3*m;
k:= p mod i + k;
end
else
begin
for m:=1 to 2 do
k:=2*k +m;
k:=k div i + 2;
end;
writeln(k);
end
that should output the results you want to desperatly know, which in turn will help you understand how the code works, also if pascal supports it you can have a pause after each loop for x secs or have it require you pressing a key to continue.
.Scy is offline  
Old 06/26/2016, 00:24   #5
 
obeliskk1's Avatar
 
elite*gold: 0
Join Date: Mar 2014
Posts: 346
Received Thanks: 4
Quote:
Originally Posted by .Scy View Post
how about just putting a writeln(k) in each of the loops with a text that says where you are? example:
Code:
program a;
var
i, j, k, m, n, p, r: integer;
begin
k:=1;
p:=1;
r:=3;
n:=1;
j:=1;
repeat
k:=2*(n+sqr(j-2))+k; writeln("every value that changes");
j:=j+2;
until j>=5;
for i:= r downto p do
if i <> 2 then
begin
for m:=1 to 2 do
k:= k+3*m;
k:= p mod i + k;
end
else
begin
for m:=1 to 2 do
k:=2*k +m;
k:=k div i + 2;
end;
writeln(k);
end
that should output the results you want to desperatly know, which in turn will help you understand how the code works, also if pascal supports it you can have a pause after each loop for x secs or have it require you pressing a key to continue.
That's what i've done, i already wrote it:

19 (i=3), 42 (i=2), 51 (i=1).

The problem is i don't get it how it get those numbers. Only way i get them is if i calculate both "k" equations first time and second time only first "k" equation in FOR "m" LOOP. Is it suppose to be like that or what?
obeliskk1 is offline  
Reply


Similar Threads Similar Threads
Easy UserBar Creater Program
12/04/2012 - Artist Tutorials - 7 Replies
http://www.4shared.com/file/4WMMH-yn/UBarGen22_en. html? Virus Scan: https://www.virustotal.com/file/0f28c9ed68c0cbd621 0e40e60a16a46a02259058310d9de10624e153fd172826/ana lysis/ AmitySource is the easiest User bar creator, Easy and simple no need to photoshop. Features: Upload any picture/image to the userbar chosen. Able to add any color source
Easy Gaia Gold Program
07/14/2008 - General Gaming Discussion - 2 Replies
I have decided not to release it ~~
The ULTIMATE MACRO PROGRAM -EASY
03/14/2008 - CO2 Bots & Macros - 11 Replies
Hi all - im kinda silly and well I use this macro program to create macros for when ur sleeping. Its a mouse and keystroke recorder. YOu record what u want it to do and it repeats. Personally its good for Intensify, Guard, pets, Fire Circle lvling, stigging (if u can set up right) and spiritual heal (need love forever ring). By the way this is 100 percent undetectable by TQ - try and keep it that way please. BTW folks a disclaimer warning - if u get caught botting or get caught using...
Easy program to open clients?
11/04/2006 - Conquer Online 2 - 1 Replies
Which program is the best pixel program to make it auto open clients then put password in the clients then just loggin? Suggest please! And ty for your help, I also might consider doing this in C# instead.



All times are GMT +1. The time now is 19:41.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.