input:- 12233344445555566666...
output:- 1=1,2=4,3=9...
Here firstno i.e 1 should be displayed and after that the
alikeno.s should be added n displayed.i.e 2+2=4 like tat it
goeson.



input:- 12233344445555566666... output:- 1=1,2=4,3=9... Here firstno i.e 1 should be displayed and..

Answer / veena (ibm)

identification division.
program-id. calculationprg.
data division.
working-storage section.

01 ws-num.
02 ws-num1 occurs n times.
03 ws-num2 pic 9(2).

01 ws-result.
02 ws-result1 occurs n times.
03 ws-result2 pic 9(2).

01 ws-calc.
02 ws-calc1 occurs n times.
03 ws-calc2 pic 9(2).
03 ws-times pic 9(2).

05 n pic 9(2) val zero.
05 ws-count pic 9(2).
05 ws-num3 pic 9(2).


Procedure division.

display 'enter the length of number you want to input'
accept n.

display 'enter the input'
perform n times
accept ws-num2(ws-count)
display 'enter next number'
ws-count = ws-count+1
end-perform.

initialise ws-count.


perform n times
ws-count = ws-count + 1
ws-num3 = ws-num2(ws-count)
if ws-calc2(ws-count) = ws-num3
ws-times(ws-count) = ws-times(ws-count) + 1
else
ws-calc2(ws-count) = ws-num3
ws-times(ws-count) = 1
end-perform.
initialise ws-count.
perform n times
ws-count = ws-count + 1
ws-result2(ws-count) = ws-calc2(ws-count) * ws-times(ws-
count)
end-perform.

initialise ws-count.
perform n times
ws-count = ws-count + 1
display ws-result2(ws-count)
end-perform.

similarly other calculation can be performed.

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More COBOL Interview Questions

Can we redefine the field of x(200) to less than 200?

0 Answers  


what is Pic 9v99 Indicates?

2 Answers  


What is the significance of 'above the line' and 'below the line'?

2 Answers   Nokia,


How do define Dymanic array in cobol how do u define single demensional arry and multidymensional arry in ur cobol.

4 Answers   Cap Gemini,


hi. This is Ram.i have one doubt.why can't we display comp-3 variables directly? let me answer quickly plez........

1 Answers  






when COMP-3 is preferrable?

3 Answers   Patni,


how can u find out just by seeing wheater it is main program or sub program ? any two ways to identify reply soon ?

2 Answers  


I need to compare two VSAM files, both having 'number' as key. If there is a matching record, write the data into another VSAM file. How will it be possible.

1 Answers   DSRC,


What does MAXCC 3 means? It is used in one my codes.

2 Answers   Wipro,


What type of Call you would use if you don;t want the control back to the calling program?

8 Answers   TCS,


How you can characterize tables in cobol?

0 Answers  


How can we find that module can be called – whether DYNAMICALLY or STATICALLY?

0 Answers  


Categories