Suppose I have a number series like 1^1,2^2,3^3,4^4...i.e,1,4,27,256..
and pattern like
1
101
1001
10001
is there any functions to solve powers?
This was asked for me in IBm technical interview
How to handle number series logics in cobol pgm
- dick scherrer
- Global moderator
- Posts: 6268
- Joined: Sat Jun 09, 2007 8:58 am
Re: How to handle number series logics in cobol pgm
Hello and welcome to the forum,
You need to write the code and post here when you get stuck.
People here will help you work thru the code but will not write it for you.
We are here to help people learn, not do the work for them.
You need to write the code and post here when you get stuck.
People here will help you work thru the code but will not write it for you.
We are here to help people learn, not do the work for them.
Hope this helps,
d.sch.
d.sch.
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: How to handle number series logics in cobol pgm
What did your search of the Language Reference manual tell you? You did search the manual before posting, right?
Re: How to handle number series logics in cobol pgm
Yeah robert i found tat the logics works out with perform n compute statement..
Plzz check my logic
1, number series 1,4,27,
data division
01 i pic 9(5)
procedure division
move 0 to i.
compute i=i+1
perform until i times
compute i=i*i
end-perform
display i
2,number pattern
data division
01 i pic 9(3).
01 j pic 9(3).
procedure division
move 1 to i,j.
perform para-1 varying i from 1 by 1 until i<4 after varying j from 1 by 1 until j<=i
para-1
if j=1 and i=j then
display 1
else
display 0
plzz correct me if the logics are wrong thanx..
Plzz check my logic
1, number series 1,4,27,
data division
01 i pic 9(5)
procedure division
move 0 to i.
compute i=i+1
perform until i times
compute i=i*i
end-perform
display i
2,number pattern
data division
01 i pic 9(3).
01 j pic 9(3).
procedure division
move 1 to i,j.
perform para-1 varying i from 1 by 1 until i<4 after varying j from 1 by 1 until j<=i
para-1
if j=1 and i=j then
display 1
else
display 0
plzz correct me if the logics are wrong thanx..
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: How to handle number series logics in cobol pgm
Your solution number 1 will fail miserably. You cannot use I as the index for your PERFORM loop AND your result -- it can be one or the other, but not both. I haven't checked the manual to see if there's a syntax problem with PERFORM UNTIL I TIMES but I suspect even if the statement passes syntax checking, it won't do what you think it will. I would run a loop from 1 to whatever. In the loop, set X to 1, then PERFORM loop TIMES COMPUTE X = X * loop END-PERFORM
Your solution number 2 won't produce a trailing 1 -- nor will it produce a horizontal pattern. I would solve this one by noting that after the first term, the nth term becomes a 1 followed by (n-1) zeroes followed by a 1 -- and I would set up a loop using reference modification to generate a variable with the pattern. What you don't want to do is use repeated DISPLAY statements since each DISPLAY statement starts on a new line (unless you use the language construct to not do so).
Your solution number 2 won't produce a trailing 1 -- nor will it produce a horizontal pattern. I would solve this one by noting that after the first term, the nth term becomes a 1 followed by (n-1) zeroes followed by a 1 -- and I would set up a loop using reference modification to generate a variable with the pattern. What you don't want to do is use repeated DISPLAY statements since each DISPLAY statement starts on a new line (unless you use the language construct to not do so).
Re: How to handle number series logics in cobol pgm
Table 17. Binary operators
Binary operator M
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
I can explain it to you, but i can not understand it for you.
Re: How to handle number series logics in cobol pgm
@all thank u 4 the reply...
yes guyc ..tats it..** operator works fine to get that series...and robert is there any other way other than reference modification
yes guyc ..tats it..** operator works fine to get that series...and robert is there any other way other than reference modification
Re: How to handle number series logics in cobol pgm
Pseudo code :
if i =1 then 1 else (10 ** i + 1)
if i =1 then 1 else (10 ** i + 1)
I can explain it to you, but i can not understand it for you.
-
- Global moderator
- Posts: 3720
- Joined: Sat Dec 19, 2009 8:32 pm
- Skillset: Systems programming, SAS, COBOL, CICS, JCL, SMS, VSAM, etc.
- Referer: other forum
- Location: Dubuque, Iowa, USA
Re: How to handle number series logics in cobol pgm
You could use an array, of course, or you could experiment with DISPLAY ... WITH NO ADVANCING.
What's the reluctance to use reference modification? It is a very good technique for dealing with certain problems.
What's the reluctance to use reference modification? It is a very good technique for dealing with certain problems.
Re: How to handle number series logics in cobol pgm
Thanks robert..i have another doubt regarding this . Can we do arthematic operations on the identifier that we use along with perform statements like if i want to display pattern like
1
2 4
3 6 9
is the follw.. method correct
data
01 number1 pic 9(2) value zero
01 number1 pic 9(2) value zero
01 number1 pic 9(2)
procedure
perform varying number1 1 by 1 until number1<=3
perform varying number2 1 by 1 until number2<=number1
compute number3=number1*number2
display 'bb' number3 with no advancing. //bb - two blank spaces
end-perform
end-perform
stop-run
Do chk thhe code , and correct me if am wrng..
thank u
1
2 4
3 6 9
is the follw.. method correct
data
01 number1 pic 9(2) value zero
01 number1 pic 9(2) value zero
01 number1 pic 9(2)
procedure
perform varying number1 1 by 1 until number1<=3
perform varying number2 1 by 1 until number2<=number1
compute number3=number1*number2
display 'bb' number3 with no advancing. //bb - two blank spaces
end-perform
end-perform
stop-run
Do chk thhe code , and correct me if am wrng..

-
- Similar Topics
- Replies
- Views
- Last post
-
-
compare number lines of two dataset
by samb01 » Wed Nov 13, 2024 8:46 pm » in DFSORT/ICETOOL/ICEGENER - 6
- 2140
-
by sergeyken
View the latest post
Fri Nov 15, 2024 12:41 pm
-
-
- 2
- 4481
-
by sergeyken
View the latest post
Sat Nov 11, 2023 3:01 am
-
- 12
- 12757
-
by Robert Sample
View the latest post
Thu Dec 15, 2022 9:28 pm
-
- 1
- 4033
-
by Leixner
View the latest post
Thu Sep 15, 2022 3:33 am
-
- 2
- 3166
-
by enrico-sorichetti
View the latest post
Mon Oct 30, 2023 6:25 pm